Custom_exec_cb prevents lv_anim_del(obj, NULL)

Looking at the code, I see:

static inline void lv_anim_set_custom_exec_cb(lv_anim_t * a, lv_anim_custom_exec_cb_t exec_cb)
    a->var     = a;
    a->exec_cb = (lv_anim_exec_xcb_t)exec_cb;

This block allows us to pass in some data via user_data, and fetch it back out when calling the callback. This works great for writing language bindings, but comes with a notable drawback: the var is overwritten, causing the object-being-animated to no longer clean up the animation automatically during lv_obj_del.

Would it be possible to consolidate the custom and non-custom callbacks into one:

  1. Do not overwrite a->var
  2. Always pass lv_anim_t* via the animation callback to the callback function
  3. Users can fetch the object being animated via a->var in the callback function

By not overwriting a->var we can avoid two tricky bugs: (1) the location of your lv_anim_t struct cannot move in memory before calling lv_anim_start, and (2) we retain the automatic deletion of animations during object deletion.

I agree that it’s a problem. I think the simplest would be to add an
lv_anim_custom_exec_cb_t custom_exec_cb member to lv_anim_t and the animation engine would call the one which is was set.

cc @amirgon

1 Like

Thanks @kisvegabor - that sounds like a good approach to me as well.

Great! I added it to the ROADMAP fir v9: