_ui_screen_change crashes if called on permanent screen with init function

The code generator includes an init call or NULL depending on if it’s changing to a temporary screen or not. However, this function is called also by manual code and requires the developer to specify the init function or not. If the type of screen gets toggled in the UI, the manual code can be out of sync and cause a crash. I would like to see the internals of _ui_screen_change check if the screen already exists before calling the init method. This will improve resiliency. Currently I wrap these calls in this code to make it more stable:

        if (lv_obj_is_valid(ui_WifiScreen))
            _ui_screen_change(&ui_WifiScreen, LV_SCR_LOAD_ANIM_FADE_IN, 100, 0, NULL);
        else
            _ui_screen_change(&ui_WifiScreen, LV_SCR_LOAD_ANIM_FADE_IN, 100, 0, &ui_WifiScreen_screen_init);

The _ui_screen_change() function already checks if the screen object has NULL pointer or not, and if it’s NULL it first creates the screen and its children by calling its init function, then loads the screen.
So in case of temporary screens which are already abandoned/deleted (and so set to NULL by their handle in ‘scr_unloaded_delete’ callback) they get created automatically first, only then loaded by lv_scr_load in _ui_screen_change().
The LVGL function lv_obj_is_valid() called in your code even checks through all the displays and even screens if the screen exists, but I don’t think that does more in this case then checking if the screen’s pointer is NULL or not.
At least for me using the _ui_screen_change() function by always giving the screen inits (not NULLs) as last parameters worked the same way as your proposed solution which just added an extra layer of function-call.

The situation of changing temporary screens from code is better in LVGL 8.3.11. You still need to be very careful before modifying any widgets whether their parent screen really exists and the widget itself already/still exists. Switching temporary screens seem to happen in several frames and for some (about 3…5) frames of delay both screens might be existing partially. The only sure point to modify widgets is to do it from a function on LV_EVENT_SCREEN_LOADED. And if some widgets are updated continuously care must be taken to stop this frequent modification instantly if any new screen is about to replace the old one.