I’d like widget pointers for widgets on a temporary screen to be reset to NULL when the screen is deleted.
Do you see alternative options and workaround to achieve it?
I do not.
Mention some use cases
If an event handler needs to refer to a widget other than the one that triggered the event, it would be useful to be able to use the ui widget pointer global variable(lv_obj_t*) after checking for NULL and lv_obj_is_valid(), but without setting the pointer variables to NULL on screen deletion, it is unsafe.
Currently, the *_screen_init() function allocates and assigns each global widget pointer variable. However, all temporary pages are destroyed with scr_unloaded_delete_cb(), which deletes the object tree for the screen, but does not reset the widget pointers to NULL. Rarely, a dangling widget pointer will point to a newly allocated object, so that lv_obj_is_valid() returns true even after the corresponding screen has been deleted.
Fair enough, thanks for the request. It’s important indeed to avoid any chance of pointing to a reused location (rare according to the linked LVGL forum post, but still a serious problem). It surely needs discussions on our side too, how we can work around this feature seemingly missing from LVGL, without kicking out concepts that prevented this from happening until now. To check if a widget really exists (on a temporary screen) the screen should be checked as well as lv_obj_is_valid(), and this should be done very carefully now (e.g. with the aid of ‘artificial’ screen-IDs), to avoid any settings to objects whose parent screen was deleted, even during screen-transitions, which are not necessarily instant and one-shot or non-overlapping.
Thank you for your consideration. Would it work for SLS to generate a *_screen_deinit() for each screen that wraps scr_unloaded_delete_cb(), then marks each screen’s widget as NULL?
Indeed. Our project is mostly temporary screens, and we suffer from this issue quite often. Navigating between a few pages built of the same widgets very often exposes this on our system. Usually a widget will disappear as we try to lv_obj_add_flag* (obj, LV_OBJ_FLAG_HIDDEN); a dangling pointer that eventually point to a different object.
I’ve been trying to add checks for every object we adjust to also check the parent screen, but this has become unscalable as the relationship between every widget and screen must be re-verified for every Squareline Studio export. As we add more widgets and screens, this takes longer and longer. Each export needs manually reviewed in case a widget was moved from one screen to another, as this breaks the checks screen+object type checks until the screen pointer is fixed.
Would it work for SLS to add a widget_unloaded_delete_cb() to set each global widget pointer to NULL, or could SLS do some other solution to these dangling object pointers?