Merge pull request #1783 from heuripedes/master

Memleak fixes
This commit is contained in:
Twinaphex 2015-06-13 01:31:51 +02:00
commit 8cf59bbffc
3 changed files with 127 additions and 52 deletions

View File

@ -1569,10 +1569,10 @@ static void xmb_free(void *data)
free(xmb->menu_stack_old);
xmb->menu_stack_old = NULL;
if (xmb->selection_buf_old)
free(xmb->selection_buf_old);
file_list_free(xmb->selection_buf_old);
xmb->selection_buf_old = NULL;
if (xmb->horizontal_list)
free(xmb->horizontal_list);
file_list_free(xmb->horizontal_list);
xmb->horizontal_list = NULL;
gl_coord_array_free(&xmb->raster_block.carr);
@ -1865,6 +1865,22 @@ static void xmb_navigation_alphabet(size_t *unused)
xmb_selection_pointer_changed();
}
static void xmb_node_kill_animation(menu_handle_t *menu, xmb_node_t *node)
{
float *subjects[5];
if (!node)
return;
subjects[0] = &node->alpha;
subjects[1] = &node->label_alpha;
subjects[2] = &node->zoom;
subjects[3] = &node->x;
subjects[4] = &node->y;
menu_animation_kill_by_subject(menu->animation, 5, subjects);
}
static void xmb_list_insert(file_list_t *list,
const char *path, const char *unused, size_t list_size)
{
@ -1911,6 +1927,18 @@ static void xmb_list_insert(file_list_t *list,
static void xmb_list_free(file_list_t *list,
size_t idx, size_t list_size)
{
menu_handle_t *menu = menu_driver_get_ptr();
xmb_node_t *node;
if (!list || !menu)
return;
node = (xmb_node_t*)menu_list_get_userdata_at_offset(list, idx);
if (node)
xmb_node_kill_animation(menu, node);
file_list_free_userdata(list, idx);
}
static void xmb_list_cache(menu_list_type_t type, unsigned action)

View File

@ -267,141 +267,182 @@ void menu_animation_free(animation_t *animation)
free(animation);
}
static struct tween *menu_animation_get_free_slot(animation_t *animation)
{
struct tween *slot = NULL;
unsigned i;
for (i = 0; i < animation->size; ++i)
{
if (!animation->list[i].alive)
{
slot = &animation->list[i];
memset(slot, 0, sizeof(*slot));
break;
}
}
if (!slot)
{
if (animation->size >= animation->capacity)
{
animation->capacity++;
animation->list = (struct tween*)realloc(animation->list,
animation->capacity * sizeof(struct tween));
}
slot = &animation->list[animation->size++];
}
return slot;
}
void menu_animation_kill_by_subject(animation_t *animation, size_t count, const void *subjects)
{
unsigned i, j;
float **sub = (float**)subjects;
for (i = 0; i < animation->size; ++i)
{
for (j = 0; j < count; ++j)
{
if (animation->list[i].subject == sub[j])
{
animation->list[i].alive = 0;
animation->list[i].subject = NULL;
}
}
}
}
bool menu_animation_push(animation_t *animation,
float duration, float target_value, float* subject,
enum animation_easing_type easing_enum, tween_cb cb)
{
if (animation->size >= animation->capacity)
{
animation->capacity++;
animation->list = (struct tween*)realloc(animation->list,
animation->capacity * sizeof(struct tween));
}
struct tween *slot = menu_animation_get_free_slot(animation);
animation->list[animation->size].alive = 1;
animation->list[animation->size].duration = duration;
animation->list[animation->size].running_since = 0;
animation->list[animation->size].initial_value = *subject;
animation->list[animation->size].target_value = target_value;
animation->list[animation->size].subject = subject;
animation->list[animation->size].cb = cb;
slot->alive = 1;
slot->duration = duration;
slot->running_since = 0;
slot->initial_value = *subject;
slot->target_value = target_value;
slot->subject = subject;
slot->cb = cb;
switch (easing_enum)
{
case EASING_LINEAR:
animation->list[animation->size].easing = &easing_linear;
slot->easing = &easing_linear;
break;
/* Quad */
case EASING_IN_QUAD:
animation->list[animation->size].easing = &easing_in_quad;
slot->easing = &easing_in_quad;
break;
case EASING_OUT_QUAD:
animation->list[animation->size].easing = &easing_out_quad;
slot->easing = &easing_out_quad;
break;
case EASING_IN_OUT_QUAD:
animation->list[animation->size].easing = &easing_in_out_quad;
slot->easing = &easing_in_out_quad;
break;
case EASING_OUT_IN_QUAD:
animation->list[animation->size].easing = &easing_out_in_quad;
slot->easing = &easing_out_in_quad;
break;
/* Cubic */
case EASING_IN_CUBIC:
animation->list[animation->size].easing = &easing_in_cubic;
slot->easing = &easing_in_cubic;
break;
case EASING_OUT_CUBIC:
animation->list[animation->size].easing = &easing_out_cubic;
slot->easing = &easing_out_cubic;
break;
case EASING_IN_OUT_CUBIC:
animation->list[animation->size].easing = &easing_in_out_cubic;
slot->easing = &easing_in_out_cubic;
break;
case EASING_OUT_IN_CUBIC:
animation->list[animation->size].easing = &easing_out_in_cubic;
slot->easing = &easing_out_in_cubic;
break;
/* Quart */
case EASING_IN_QUART:
animation->list[animation->size].easing = &easing_in_quart;
slot->easing = &easing_in_quart;
break;
case EASING_OUT_QUART:
animation->list[animation->size].easing = &easing_out_quart;
slot->easing = &easing_out_quart;
break;
case EASING_IN_OUT_QUART:
animation->list[animation->size].easing = &easing_in_out_quart;
slot->easing = &easing_in_out_quart;
break;
case EASING_OUT_IN_QUART:
animation->list[animation->size].easing = &easing_out_in_quart;
slot->easing = &easing_out_in_quart;
break;
/* Quint */
case EASING_IN_QUINT:
animation->list[animation->size].easing = &easing_in_quint;
slot->easing = &easing_in_quint;
break;
case EASING_OUT_QUINT:
animation->list[animation->size].easing = &easing_out_quint;
slot->easing = &easing_out_quint;
break;
case EASING_IN_OUT_QUINT:
animation->list[animation->size].easing = &easing_in_out_quint;
slot->easing = &easing_in_out_quint;
break;
case EASING_OUT_IN_QUINT:
animation->list[animation->size].easing = &easing_out_in_quint;
slot->easing = &easing_out_in_quint;
break;
/* Sine */
case EASING_IN_SINE:
animation->list[animation->size].easing = &easing_in_sine;
slot->easing = &easing_in_sine;
break;
case EASING_OUT_SINE:
animation->list[animation->size].easing = &easing_out_sine;
slot->easing = &easing_out_sine;
break;
case EASING_IN_OUT_SINE:
animation->list[animation->size].easing = &easing_in_out_sine;
slot->easing = &easing_in_out_sine;
break;
case EASING_OUT_IN_SINE:
animation->list[animation->size].easing = &easing_out_in_sine;
slot->easing = &easing_out_in_sine;
break;
/* Expo */
case EASING_IN_EXPO:
animation->list[animation->size].easing = &easing_in_expo;
slot->easing = &easing_in_expo;
break;
case EASING_OUT_EXPO:
animation->list[animation->size].easing = &easing_out_expo;
slot->easing = &easing_out_expo;
break;
case EASING_IN_OUT_EXPO:
animation->list[animation->size].easing = &easing_in_out_expo;
slot->easing = &easing_in_out_expo;
break;
case EASING_OUT_IN_EXPO:
animation->list[animation->size].easing = &easing_out_in_expo;
slot->easing = &easing_out_in_expo;
break;
/* Circ */
case EASING_IN_CIRC:
animation->list[animation->size].easing = &easing_in_circ;
slot->easing = &easing_in_circ;
break;
case EASING_OUT_CIRC:
animation->list[animation->size].easing = &easing_out_circ;
slot->easing = &easing_out_circ;
break;
case EASING_IN_OUT_CIRC:
animation->list[animation->size].easing = &easing_in_out_circ;
slot->easing = &easing_in_out_circ;
break;
case EASING_OUT_IN_CIRC:
animation->list[animation->size].easing = &easing_out_in_circ;
slot->easing = &easing_out_in_circ;
break;
/* Bounce */
case EASING_IN_BOUNCE:
animation->list[animation->size].easing = &easing_in_bounce;
slot->easing = &easing_in_bounce;
break;
case EASING_OUT_BOUNCE:
animation->list[animation->size].easing = &easing_out_bounce;
slot->easing = &easing_out_bounce;
break;
case EASING_IN_OUT_BOUNCE:
animation->list[animation->size].easing = &easing_in_out_bounce;
slot->easing = &easing_in_out_bounce;
break;
case EASING_OUT_IN_BOUNCE:
animation->list[animation->size].easing = &easing_out_in_bounce;
slot->easing = &easing_out_in_bounce;
break;
default:
animation->list[animation->size].easing = NULL;
slot->easing = NULL;
break;
}
animation->size++;
return true;
}
@ -410,8 +451,12 @@ static int menu_animation_iterate(struct tween *tween, float dt,
{
if (!tween)
return -1;
if (tween->running_since >= tween->duration)
if (tween->running_since >= tween->duration || !tween->alive)
{
tween->alive = 0;
tween->subject = NULL;
return -1;
}
tween->running_since += dt;

View File

@ -96,6 +96,8 @@ enum animation_easing_type
void menu_animation_free(animation_t *animation);
void menu_animation_kill_by_subject(animation_t *animation, size_t count, const void *subjects);
bool menu_animation_push(animation_t *animation, float duration,
float target_value, float* subject,
enum animation_easing_type easing_enum, tween_cb cb);