From 836cf148606e8f33182ec024856082d82b18f320 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Tue, 21 May 2013 07:33:00 +0200 Subject: 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 --- apps/radio/radioart.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'apps/radio/radioart.c') diff --git a/apps/radio/radioart.c b/apps/radio/radioart.c index 53ed863b3b..76697c6017 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;ihandle >= 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; -- cgit v1.2.3