Temporary Screen with an infinite loop animation crashes when deleted

There is an event for Play Animation but I think there needs to be one for either Stop Animation or Delete Animation that can be called from the Unload event. Or is called automatically when the screen is deleted.

Also, squareline generates the animation as a local variable in a function, so there is no way to reference the animation object from outside it to delete it or stop playback from custom function

void My_Animation( lv_obj_t *TargetObject, int delay)
lv_anim_t PropertyAnimation_0;

I confirmed that this does not crash is the screen is not marked at Temporary. So my guess is because the animation target has been deleted and this causes the crash.

I tried doing this but it didn’t work:

void MyTemporaryScreen_UnloadStart(lv_event_t *e)
	// delete the animation
	lv_anim_del(ui_MyAnimatedObject, NULL);

We discussed this with LVGL-authors and the advise was to avoid creating animations from temporary screens, but create them separately or by screen_loaded events, so there would be more control over the creation/deletion of animations. You concluded something similar, but you told in the last post the (same? crashing?) problem still exists.
As for the supposed animation-deletion functions, we’ll discuss the possibilities.
The SquareLine documentation explicitly tells to be careful with Temporary Screens: they shouldn’t contain ‘continuous animation’.

The code you generate for the SquareLine animations encapsulates the object reference inside the creation method rather than having a global variable like all the other widgets. Having a global variable would allow interaction with the animation from outside the create function.

After checking the code of lv_anim_del() function in LVGL source-tree, it seems that you can delete (stop) the animation by setting 1st parameter to NULL and giving the executor callback function’s name instead to identify the animation. It isn’t mentioned in LVGL 8.3 documentation, just the cases when you give both the animated variable/object and the function name. But the code shows if any of them is set to NULL the other parameter will be used nevertheless to stop the matching animation.)

So you don’t need to have the animated variable/object ‘PropertyAnimation_0’ (in your latest example ‘ui_MyAnimatedObject’) to be in a global scope, the function name is enough. You can delete (stop) the animation like this before switching from temporary screen to another (tested and works):

lv_anim_del( NULL, (lv_anim_exec_xcb_t) _ui_anim_callback_set_x );

(The 2nd argument - function name - should be rewritten to your actual animator function in your code. The casting is necessary to avoid warnings thrown by lv_anim_del(). )