I’m trying to figure out the lifetime/ownership/etc of the various parts of animations. In my case I have an animation I want to turn on and off depending on state. So I’m trying to figure out which variables I need to keep in my state and which I can allocate on the stack and then forget about.
Starting with something like:
lv_anim_t * a = lv_mem_alloc(...); lv_anim_init(a); state->animation = a;
…I’d then set value params (start, end, etc.) that get passed by value anyway. But what about the path? I would normally assume that a struct needs to live as long as whatever takes it, so I’d allocate that on the heap too. However, when I look at the source for
lv_anim.c I notice that it’s
memcpy-ing the contents under the hood. So could I actually do:
lv_anim_path_t path; // init, set callback lv_anim_set_path(a, &path);
…and not worry about use of stack allocated memory for a heap allocated animation?
My second question is about stopping and restarting animations. There’s a start animation call
lv_anim_start(), but to stop animations you delete them with
lv_anim_del(). The latter function takes the variable and function but not the animation, because the underlying list only stores the first two things anyway. So does this mean I can reuse the animation variable and repeatedly invoke
lv_anim_del() without any other reconfiguration in between?