diff options
| author | Thomas Martitz <kugel@rockbox.org> | 2013-05-21 07:33:00 +0200 |
|---|---|---|
| committer | Thomas Martitz <kugel@rockbox.org> | 2013-06-09 17:44:11 +0200 |
| commit | 836cf148606e8f33182ec024856082d82b18f320 (patch) | |
| tree | 465cad067fee30bd9ad88e2f338be81b66e69bfa | |
| parent | 58b4e71d3244b3c433e1fd3b494d17379bf57c48 (diff) | |
| download | rockbox-836cf148606e8f33182ec024856082d82b18f320.zip rockbox-836cf148606e8f33182ec024856082d82b18f320.tar.gz rockbox-836cf148606e8f33182ec024856082d82b18f320.tar.bz2 rockbox-836cf148606e8f33182ec024856082d82b18f320.tar.xz | |
Fix multiple problems in radioart.c
The code was pretty broken with regard to the handle management of radio art
images, e.g. passing the wrong data to bufopen().
Change-Id: I3480f40bce81af05d14dbf045a78485c857fb261
| -rw-r--r-- | apps/radio/radioart.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/apps/radio/radioart.c b/apps/radio/radioart.c index 53ed863..76697c6 100644 --- a/apps/radio/radioart.c +++ b/apps/radio/radioart.c @@ -44,21 +44,24 @@ struct radioart { static char* buf; static struct radioart radioart[MAX_RADIOART_IMAGES]; -static int find_oldest_image(void) +static int find_oldest_image_index(void) { int i; - long oldest_tick = radioart[0].last_tick; - int oldest_idx = 0; - for(i=1;i<MAX_RADIOART_IMAGES;i++) + long oldest_tick = current_tick; + int oldest_idx = -1; + for(i = 0; ARRAYLEN(radioart); i++) { - if (radioart[i].last_tick < oldest_tick) + struct radioart *ra = &radioart[i]; + /* last_tick is only valid if it's actually loaded, i.e. valid handle */ + if (ra->handle >= 0 && TIME_BEFORE(ra->last_tick, oldest_tick)) { - oldest_tick = radioart[i].last_tick; + oldest_tick = ra->last_tick; oldest_idx = i; } } return oldest_idx; } + static int load_radioart_image(struct radioart *ra, const char* preset_name, struct dim *dim) { @@ -86,9 +89,12 @@ static int load_radioart_image(struct radioart *ra, const char* preset_name, ra->handle = bufopen(path, 0, TYPE_BITMAP, &user_data); if (ra->handle == ERR_BUFFER_FULL) { - int i = find_oldest_image(); - bufclose(i); - ra->handle = bufopen(path, 0, TYPE_BITMAP, &ra->dim); + int i = find_oldest_image_index(); + if (i != -1) + { + bufclose(radioart[i].handle); + ra->handle = bufopen(path, 0, TYPE_BITMAP, &user_data); + } } #ifndef HAVE_NOISY_IDLE_MODE cpu_idle_mode(true); @@ -126,10 +132,13 @@ int radio_get_art_hid(struct dim *requested_dim) } else { - int i = find_oldest_image(); - bufclose(radioart[i].handle); - return load_radioart_image(&radioart[i], - preset_name, requested_dim); + int i = find_oldest_image_index(); + if (i != -1) + { + bufclose(radioart[i].handle); + return load_radioart_image(&radioart[i], + preset_name, requested_dim); + } } return -1; |