summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2013-05-21 07:33:00 +0200
committerThomas Martitz <kugel@rockbox.org>2013-06-09 17:44:11 +0200
commit836cf148606e8f33182ec024856082d82b18f320 (patch)
tree465cad067fee30bd9ad88e2f338be81b66e69bfa
parent58b4e71d3244b3c433e1fd3b494d17379bf57c48 (diff)
downloadrockbox-836cf148606e8f33182ec024856082d82b18f320.tar.gz
rockbox-836cf148606e8f33182ec024856082d82b18f320.zip
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.c35
1 files changed, 22 insertions, 13 deletions
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 {
44static char* buf; 44static char* buf;
45static struct radioart radioart[MAX_RADIOART_IMAGES]; 45static struct radioart radioart[MAX_RADIOART_IMAGES];
46 46
47static int find_oldest_image(void) 47static int find_oldest_image_index(void)
48{ 48{
49 int i; 49 int i;
50 long oldest_tick = radioart[0].last_tick; 50 long oldest_tick = current_tick;
51 int oldest_idx = 0; 51 int oldest_idx = -1;
52 for(i=1;i<MAX_RADIOART_IMAGES;i++) 52 for(i = 0; ARRAYLEN(radioart); i++)
53 { 53 {
54 if (radioart[i].last_tick < oldest_tick) 54 struct radioart *ra = &radioart[i];
55 /* last_tick is only valid if it's actually loaded, i.e. valid handle */
56 if (ra->handle >= 0 && TIME_BEFORE(ra->last_tick, oldest_tick))
55 { 57 {
56 oldest_tick = radioart[i].last_tick; 58 oldest_tick = ra->last_tick;
57 oldest_idx = i; 59 oldest_idx = i;
58 } 60 }
59 } 61 }
60 return oldest_idx; 62 return oldest_idx;
61} 63}
64
62static int load_radioart_image(struct radioart *ra, const char* preset_name, 65static int load_radioart_image(struct radioart *ra, const char* preset_name,
63 struct dim *dim) 66 struct dim *dim)
64{ 67{
@@ -86,9 +89,12 @@ static int load_radioart_image(struct radioart *ra, const char* preset_name,
86 ra->handle = bufopen(path, 0, TYPE_BITMAP, &user_data); 89 ra->handle = bufopen(path, 0, TYPE_BITMAP, &user_data);
87 if (ra->handle == ERR_BUFFER_FULL) 90 if (ra->handle == ERR_BUFFER_FULL)
88 { 91 {
89 int i = find_oldest_image(); 92 int i = find_oldest_image_index();
90 bufclose(i); 93 if (i != -1)
91 ra->handle = bufopen(path, 0, TYPE_BITMAP, &ra->dim); 94 {
95 bufclose(radioart[i].handle);
96 ra->handle = bufopen(path, 0, TYPE_BITMAP, &user_data);
97 }
92 } 98 }
93#ifndef HAVE_NOISY_IDLE_MODE 99#ifndef HAVE_NOISY_IDLE_MODE
94 cpu_idle_mode(true); 100 cpu_idle_mode(true);
@@ -126,10 +132,13 @@ int radio_get_art_hid(struct dim *requested_dim)
126 } 132 }
127 else 133 else
128 { 134 {
129 int i = find_oldest_image(); 135 int i = find_oldest_image_index();
130 bufclose(radioart[i].handle); 136 if (i != -1)
131 return load_radioart_image(&radioart[i], 137 {
132 preset_name, requested_dim); 138 bufclose(radioart[i].handle);
139 return load_radioart_image(&radioart[i],
140 preset_name, requested_dim);
141 }
133 } 142 }
134 143
135 return -1; 144 return -1;