How to change between screens?

Not sure of what you what I do but I tried your code and it’s the same issue.
However, I found from where it comes. It’s from create_screen_2() function. So the problem is here:

lv_obj_t * create_screen_2(bool ErrorMDP)
{
    lv_obj_t * screen_MotdePasse = lv_obj_create(NULL);
    lv_obj_add_event_cb(screen_MotdePasse, scr_unloaded_delete_cb, LV_EVENT_SCREEN_UNLOADED, &screen_MotdePasse);

    //Some other code here to add elements to screen

    return screen_MotdePasse;

To use this function, I did this:

screen_MotdePasse_Initial1 = create_screen_2(0);
lv_scr_load(screen_MotdePasse_Initial1);

Just see you edited your last message when I reply to it.
I don’t understand the last part

Maybe go back to start, you try delete xisted screen, we show you examples from Squareline generated code.

void ui_Screen4_screen_init(void)
{
    ui_Screen4 = lv_obj_create(NULL);
    lv_obj_add_event_cb(ui_Screen4, scr_unloaded_delete_cb, LV_EVENT_SCREEN_UNLOADED, &ui_Screen4);

this works ok because ui_Screen4 is global object variable exist anytime.

your code

`lv_obj_t * create_screen_2(bool ErrorMDP)
{
    lv_obj_t * screen_MotdePasse = lv_obj_create(NULL);
    lv_obj_add_event_cb(screen_MotdePasse, scr_unloaded_delete_cb, LV_EVENT_SCREEN_UNLOADED, &screen_MotdePasse);

    //Some other code here to add elements to screen

    return screen_MotdePasse;`

must Sigfault because UNLOADED, &screen_MotdePasse); is local object after exit this func never exist, or better say is used for other and store other data on this &

Basic in C

Strange decision in the implementation of create_screen_(). Somewhere a global variable is used to create a screen, somewhere a local one.

using LV_UNUSED in this code is not a problem, although it doesn’t make sense.

#define LV_UNUSED(x) ((void)x)

This macro performs a type conversion of a variable and is used in examples to prevent the warning that the variable is not used from appearing.

@HardHeavy
anytime you call updateStatus_Chauffe() your appl creates new label

text_etatCH = lv_label_create(screen_General1);

Thus, after a certain number of calls, the available memory will run out and text_etatCH will take the value NULL, which can potentially lead to a program crash. For example, I don’t know how the program will behave when trying to add a style

lv_obj_add_style(text_etatCH, &style_chauffage, 0);

when text_etatCH = NULL.
Is that what you intended?

Also

if (enterPrgChauffe != 1) {spinner = lv_spinner_create(screen_General1);}

may create a new spinner when choix_PrgChauffe() called, which can lead to the same problems.

->OK, I did not see that before.

I remember what you said before, but as I said upper, I need to create some screens that are similar, so I’m seaching a way to avoid to create same 10x "create_screen1()’ functions.

->Do you speak about the call of the function or in the function itself ?

->No, that’s not what I want and I did not expect that as there is only one label of text_etatCH shown on screen, not two or many. I should just call

text_etatCH = lv_label_create(screen_General1);

once ?

->But because of “enterPrgChauffe” (global variable) is set to ‘1’ after, it won’t create multiples spinner then. Or am I wrong ?

I mean create_screen_2() uses local screen_MotdePasse variable

lv_obj_t * create_screen_2(bool ErrorMDP)
{
    lv_obj_t * screen_MotdePasse = lv_obj_create(NULL);
...
    return screen_MotdePasse;
}

while create_screen_3() uses global screen_MotdePasse_Erreur

void create_screen_3(bool ErrorMDP)
{
    screen_MotdePasse_Erreur = lv_obj_create(NULL);
...
}

since the content of both functions is almost identical, I can suggest combining them into one

lv_obj_t * create_screen(bool ErrorMDP)
{
    lv_obj_t * screen = lv_obj_create(NULL);
...
    return screen;
}

if you need only one object create them once. I can suggest put it in create_screen_1() where all screen_General1 objects are initialized. Similarly for the spinner, create it along with all the screen_General1 objects. As far as I can see, the parameters of these objects (size, position, styles) do not change during the program.

All these sets of created labels will not be visible, because they are created with the same parameters (size, position and even text). Therefore they will simply overlap each other and you will not see that there are 100 of them. You will see only the top one.

To start, I know that “create_screen_2()” and “create_screen_3()” are almost same since it’s a copy/paste and just some minor changes were added to the second. That’s why I asked before how to implement similar screens without created almost same multiples “create_screen_2()”. But because it doesn’t work for now with

lv_obj_t * create_screen_2(bool ErrorMDP)

and as I need “screen_MotdePasse_Erreur” created in “create_screen_3()”, I keep it to do my test.

To continue, I have something I cannot understand in your reply. You started to say that my create_screen_2() function is not the best, and then suggest to do the exact same implementation for the screen in you “create_screen”.

But that’ already what it is done for now. Do you mean I should create 2 functions like:

void init_screen_1()
{
   text = lv_label_create(screen_General1)
   //etc for all objects
}

void create_screen_1()
{
   lv_label_set_text(text_Etat_Salon, "ON");
}

In fact, they were overlapped before and I can see them as the text changed sometimes. So, I change my code and thought it was ok now, but seems not.

There is no problem to use one function to create multiple screens

lv_obj_t * create_screen_blabla(bool ErrorMDP)
{
   lv_obj_t * screen = lv_obj_create(NULL);
  //  create & configure screen objects depending on ErrorMDP
  .............
  return screen;
}
......
  screen_MotdePasse_Initial1 = create_screen_blabla(0);
......
  screen_MotdePasse_Erreur = create_screen_blabla(1);

If you need only one label text_etatCH (child of screen_General1) so create & configure it where parent created, i.e.

void create_screen_1(byte etat_prgChauffe)
{
  screen_General1 = lv_obj_create(NULL);
.....
  text_etatCH = lv_label_create(screen_General1);
....
}

I don’t understand why the creation of this label was moved to another function, why it can’t be created when creating all the screen elements.