forked from len0rd/rockbox
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
This commit is contained in:
parent
58b4e71d32
commit
836cf14860
1 changed files with 22 additions and 13 deletions
|
@ -44,21 +44,24 @@ struct radioart {
|
||||||
static char* buf;
|
static char* buf;
|
||||||
static struct radioart radioart[MAX_RADIOART_IMAGES];
|
static struct radioart radioart[MAX_RADIOART_IMAGES];
|
||||||
|
|
||||||
static int find_oldest_image(void)
|
static int find_oldest_image_index(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
long oldest_tick = radioart[0].last_tick;
|
long oldest_tick = current_tick;
|
||||||
int oldest_idx = 0;
|
int oldest_idx = -1;
|
||||||
for(i=1;i<MAX_RADIOART_IMAGES;i++)
|
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;
|
oldest_idx = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return oldest_idx;
|
return oldest_idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int load_radioart_image(struct radioart *ra, const char* preset_name,
|
static int load_radioart_image(struct radioart *ra, const char* preset_name,
|
||||||
struct dim *dim)
|
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);
|
ra->handle = bufopen(path, 0, TYPE_BITMAP, &user_data);
|
||||||
if (ra->handle == ERR_BUFFER_FULL)
|
if (ra->handle == ERR_BUFFER_FULL)
|
||||||
{
|
{
|
||||||
int i = find_oldest_image();
|
int i = find_oldest_image_index();
|
||||||
bufclose(i);
|
if (i != -1)
|
||||||
ra->handle = bufopen(path, 0, TYPE_BITMAP, &ra->dim);
|
{
|
||||||
|
bufclose(radioart[i].handle);
|
||||||
|
ra->handle = bufopen(path, 0, TYPE_BITMAP, &user_data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#ifndef HAVE_NOISY_IDLE_MODE
|
#ifndef HAVE_NOISY_IDLE_MODE
|
||||||
cpu_idle_mode(true);
|
cpu_idle_mode(true);
|
||||||
|
@ -126,10 +132,13 @@ int radio_get_art_hid(struct dim *requested_dim)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i = find_oldest_image();
|
int i = find_oldest_image_index();
|
||||||
bufclose(radioart[i].handle);
|
if (i != -1)
|
||||||
return load_radioart_image(&radioart[i],
|
{
|
||||||
preset_name, requested_dim);
|
bufclose(radioart[i].handle);
|
||||||
|
return load_radioart_image(&radioart[i],
|
||||||
|
preset_name, requested_dim);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue