-
Hello,
I am experiencing an issue with animation management in LVGL 9.5 on an ESP32-S3.
I have multiple animations running simultaneously. I want to stop or delete only one specific animation without affecting any other running animations.
I have tried the following approaches:
lv_anim_custom_delete(detect_anim, NULL);And:
lv_anim_delete(ui_detectgif, NULL);However, when I execute the stop function, all other running animations also stop.
My questions are:
-
What is the correct way to delete only one specific animation in LVGL 9.5?
-
Is it possible to delete an animation directly using its
lv_anim_t *pointer? -
Can
lv_anim_delete(var, exec_cb)unintentionally delete other animations? -
What is the recommended approach for managing multiple independent animations simultaneously?
I would appreciate any suggestions or explanations.
Thank you.
-
Hi, thanks for the detailed report and the video. What you’re seeing comes from how lv_anim_delete() matches animations in LVGL 9.5:
if((a->var == var || var == NULL) && (a->exec_cb == exec_cb || exec_cb == NULL))
NULL acts as a wildcard, so lv_anim_delete(NULL, NULL) deletes every running animation. lv_anim_custom_delete(a, cb) is just lv_anim_delete(a ? a->var : NULL, cb).
Animations generated by SquareLine Studio keep their target object in user_data and use a custom exec callback, so their var is NULL. That means:
lv_anim_custom_delete(detect_anim, NULL)ends up aslv_anim_delete(NULL, NULL)and stops everything (answer to Q3: yes).lv_anim_delete(ui_detectgif, NULL)only deletes animations whosevaris that object, such as an Animated Image’s own animation. If it stops everything,ui_detectgifwas most likelyNULLat that moment (screen not created yet, or already deleted).
Deleting one specific animation (Q1, Q2): LVGL has a built-in way. Set the animation’s var to the descriptor itself; lv_anim_start() then replaces it with the running copy, which makes it a unique key:
static lv_anim_t * detect_anim = NULL;
static void detect_anim_deleted(lv_anim_t * a) { detect_anim = NULL; }
void start_detect_anim(void)
{
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, &a); /* becomes the running anim's own pointer */
lv_anim_set_custom_exec_cb(&a, my_exec_cb);
lv_anim_set_values(&a, 0, 100);
lv_anim_set_duration(&a, 1000);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_set_deleted_cb(&a, detect_anim_deleted);
detect_anim = lv_anim_start(&a);
}
void stop_detect_anim(void)
{
if(detect_anim) lv_anim_delete(detect_anim, NULL); /* deletes only this one */
}
Always check the pointer for NULL before deleting. The deleted_cb clears it when the animation ends on its own, so you never pass a stale pointer or a NULL wildcard.
Managing several animations (Q4): give each animation a unique var: either the target object together with lv_anim_set_exec_cb(), deleted with lv_anim_delete(obj, cb), or the self-pointer pattern above. Never call lv_anim_delete() / lv_anim_custom_delete() with a value that may be NULL. Animations created from Studio’s Animation panel can’t be stopped one by one, because the generated function doesn’t return the animation pointer. Write the ones you need to stop yourself, e.g. in ui_events.c, which isn’t overwritten on export. If ui_detectgif is an Animated Image widget, lv_anim_delete(ui_detectgif, NULL) (with a valid pointer) stops only that widget’s own animation.