Non-temporary screen with an infinite loop animation leaks on LV_EVENT_SCREEN_LOAD_START

What do you want to achieve?

I would like my LVGL heap returned to the original state after closing each screen.

Here is the screen event code:

void ui_event_SomeScreen(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);

    if(event_code == LV_EVENT_SCREEN_LOAD_START) {
        WaitingIconPulse_Animation(ui_SomeScreenIcon, 0);
        ui_SomeScreenLoading(e);
    }
    if(event_code == LV_EVENT_SCREEN_UNLOAD_START) {
        ui_SomeScreenClosing(e);
    }
    if(event_code == LV_EVENT_SCREEN_UNLOADED) {
        ui_SomeScreenClosed(e);
    }
    if(event_code == LV_EVENT_SCREEN_LOADED) {
        ui_SomeScreenLoaded(e);
    }
}

Here is the animation code:

lv_anim_t * WaitingIconPulse_Animation(lv_obj_t * TargetObject, int delay)
{
    lv_anim_t * out_anim;
    ui_anim_user_data_t * PropertyAnimation_0_user_data = lv_mem_alloc(sizeof(ui_anim_user_data_t));
    PropertyAnimation_0_user_data->target = TargetObject;
    PropertyAnimation_0_user_data->val = -1;
    lv_anim_t PropertyAnimation_0;
    lv_anim_init(&PropertyAnimation_0);
    lv_anim_set_time(&PropertyAnimation_0, 1000);
    lv_anim_set_user_data(&PropertyAnimation_0, PropertyAnimation_0_user_data);
    lv_anim_set_custom_exec_cb(&PropertyAnimation_0, _ui_anim_callback_set_opacity);
    lv_anim_set_values(&PropertyAnimation_0, 255, 100);
    lv_anim_set_path_cb(&PropertyAnimation_0, lv_anim_path_linear);
    lv_anim_set_delay(&PropertyAnimation_0, delay + 0);
    lv_anim_set_deleted_cb(&PropertyAnimation_0, _ui_anim_callback_free_user_data);
    lv_anim_set_playback_time(&PropertyAnimation_0, 0);
    lv_anim_set_playback_delay(&PropertyAnimation_0, 0);
    lv_anim_set_repeat_count(&PropertyAnimation_0, LV_ANIM_REPEAT_INFINITE);
    lv_anim_set_repeat_delay(&PropertyAnimation_0, 1000);
    lv_anim_set_early_apply(&PropertyAnimation_0, false);
    out_anim = lv_anim_start(&PropertyAnimation_0);//Never freed
    ui_anim_user_data_t * PropertyAnimation_1_user_data = lv_mem_alloc(sizeof(ui_anim_user_data_t));
    PropertyAnimation_1_user_data->target = TargetObject;
    PropertyAnimation_1_user_data->val = -1;
    lv_anim_t PropertyAnimation_1;
    lv_anim_init(&PropertyAnimation_1);
    lv_anim_set_time(&PropertyAnimation_1, 1000);
    lv_anim_set_user_data(&PropertyAnimation_1, PropertyAnimation_1_user_data);
    lv_anim_set_custom_exec_cb(&PropertyAnimation_1, _ui_anim_callback_set_opacity);
    lv_anim_set_values(&PropertyAnimation_1, 100, 255);
    lv_anim_set_path_cb(&PropertyAnimation_1, lv_anim_path_linear);
    lv_anim_set_delay(&PropertyAnimation_1, delay + 1000);
    lv_anim_set_deleted_cb(&PropertyAnimation_1, _ui_anim_callback_free_user_data);
    lv_anim_set_playback_time(&PropertyAnimation_1, 0);
    lv_anim_set_playback_delay(&PropertyAnimation_1, 0);
    lv_anim_set_repeat_count(&PropertyAnimation_1, LV_ANIM_REPEAT_INFINITE);
    lv_anim_set_repeat_delay(&PropertyAnimation_1, 1000);
    lv_anim_set_early_apply(&PropertyAnimation_1, false);
    out_anim = lv_anim_start(&PropertyAnimation_1);//Never freed

    return out_anim;
}

When using persistent-screens, it appears each time the user reaches the screen the LV_EVENT_SCREEN_LOAD_START event triggers creation of new animations, but these are never freed on screen closure. This also appears to be the cause of some strange UI behaviours when multiple copies of the same animation are firing and overlapping each other.

Others

  • SquareLine Studio version: 1.5.3
  • Operating system: Windows 11
  • Target hardware: Custom ESP32 solution