Set deleted objects to NULL

What do you want to achieve?

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.

Please see Lv_obj_is_valid() doesn't work 100% of the time - #2 by kisvegabor - General discussion - LVGL Forum

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?