Problem with lv_scr_load();

Description

i have event handler with call screen function between 2 function (work with file). and i have problem - screen not run till execute function send_to_CutFile();

What MCU/Processor/Board and compiler are you using?

platformio, ESP32, Tft_espi

What do you want to achieve?

i need to call function send_to_CutFile() after load screen

What have you tried so far?

  1. i separated creating a screen and load screen;

create_CutScreen();
file_size(SD, fileSelectToCut);
lv_scr_load(CutScreen);

send_to_CutFile(SD, fileSelectToCut);

  1. i inserted send_to_CutFile(SD, fileSelectToCut); into function create_CutScreen();

Code to reproduce

The code block(s) should be between ```c and ``` tags:

if(event == LV_EVENT_VALUE_CHANGED) {

                

        if (String(lv_msgbox_get_active_btn_text(obj)) == "Ok"){

            lv_msgbox_start_auto_close(obj, 0);

            

            file_size(SD, fileSelectToCut);

            create_CutScreen();

            send_to_CutFile(SD, fileSelectToCut);

        }

where create_CutScreen() is

static void create_CutScreen(void)         
{

    // ********************************************************************************
    // ********************************************************************************
    // ****         Start CutMenu        - чтение и посылка файла    ******
    // ********************************************************************************
    // ********************************************************************************



    style_init();

    lv_style_init(&stylePage);
    

    lv_style_set_radius(&stylePage, LV_STATE_DEFAULT, 10);                   //Радиус
    lv_style_set_bg_opa(&stylePage, LV_STATE_DEFAULT, LV_OPA_COVER);          //прозрачность  LV_STATE_DEFAULT  - состояние по умолчанию, LV_OPA_COVER - 0прозрачности   
    lv_style_set_bg_color(&stylePage, LV_STATE_DEFAULT, LV_COLOR_NAVY);       //цвет фона 

    lv_style_set_border_width(&stylePage, LV_STATE_DEFAULT, 3);               //толщина рамки
    lv_style_set_border_color(&stylePage, LV_STATE_DEFAULT, LV_COLOR_MAGENTA);  //цвет рамки 
 
    lv_style_set_text_color(&stylePage, LV_STATE_DEFAULT, LV_COLOR_WHITE);

    //lv_style_set_image_recolor_opa(&stylePage, LV_STATE_DEFAULT,255);                  // задание прозрачности иконки. прозрачность разрешает менять цвет
    //lv_style_set_image_recolor(&stylePage, LV_STATE_DEFAULT, LV_COLOR_WHITE);            // задание цвета иконки
    //lv_style_set_image_recolor(&stylePage, LV_STATE_PRESSED, LV_COLOR_LIME);  



    lv_obj_t * prev_scr = lv_scr_act();                 //  удаление предыдущего экрана
    lv_obj_del_async(prev_scr);                         // 


    lv_obj_t * CutScreen = lv_obj_create(NULL, NULL);
    lv_scr_load(CutScreen);
 
                                                         // создание экрана
    lv_obj_add_style(CutScreen, LV_OBJ_PART_MAIN, &styleScreen);                                              // придать стиль &styleSreen кнопки экрану  
  
  
    lv_obj_t * CutScreen_icon = lv_img_create(CutScreen, NULL);                                                 // создание картинки фона screen1_icon  для экрана Screen1
   


    lv_img_set_src(CutScreen_icon, &pict_fon);             // привязка файла pict_fon к screen1_icon 
   
                                                 
    lv_obj_align(CutScreen_icon, CutScreen, LV_ALIGN_CENTER, 0, 0);  

    // ********************************************************************************
    // ****    Footer1 (FOOTER)      ******
    // ********************************************************************************

    
    lv_obj_t * Footer1 = lv_obj_create(CutScreen, NULL);                           //Создание полоски сверху экрана    
    
    lv_obj_set_height(Footer1, 20);                                                   //толщина полоски
    lv_obj_set_width(Footer1, screenWidth);                                           //длина полоски
    
    lv_obj_add_style(Footer1, LV_OBJ_PART_MAIN, &styleFooter);                        //придать стиль &screenWidth для Footer1  
    lv_obj_align(Footer1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);                        //Выравнивание низ, середина


    lv_obj_t * Footer_label = lv_label_create(Footer1, NULL);                         // создание подписи Footer_label на кнопке Footer_label
    lv_label_set_text(Footer_label, "X:0000 Y:0000 A:0000 B:0000");                   // текст подписи 
    lv_obj_align(Footer_label, NULL, LV_ALIGN_IN_TOP_LEFT, 5, 1);                     // выравнивание текста 

    lv_obj_t * Footer_label2 = lv_label_create(Footer1, NULL);                        // создание подписи Footer_label2 на кнопке Footer_label
    lv_label_set_text(Footer_label2, "Status: IDLE");                                 // текст подписи 
    lv_obj_align(Footer_label2, NULL, LV_ALIGN_IN_TOP_RIGHT, -5, 1);                  // выравнивание текста 


}

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

It’s difficult to tell exactly what the problem is here, but check that you don’t have any blocking functions anywhere in this call chain.

i added test pointer (serial.println) into function create_CutScreen :

Serial.println(“1. before lv_obj_create”);
lv_obj_t * prev_scr = lv_scr_act(); // удаление предыдущего экрана
lv_obj_del_async(prev_scr); //
lv_obj_t * CutScreen = lv_obj_create(NULL, NULL);
Serial.println(“2. after lv_obj_create”);

Serial.println(“3. before lv_scr_load”);

lv_scr_load(CutScreen);

Serial.println(“4. after lv_scr_load”);

and into event_handler:

file_size(SD, fileSelectToCut);
create_CutScreen();

Serial.println(“5. before send_to_CutFile”);
send_to_CutFile(SD, fileSelectToCut);
Serial.println(“6. after send_to_CutFile”);

and received in comm port correct order:
total_line: 9

  1. before lv_obj_create
  2. after lv_obj_create
  3. before lv_scr_load
  4. after lv_scr_load
  5. before send_to_CutFile
    Step: 11.11
    total_line: 9
    Read from file:
    rezka1
    rezka2
    rezka3
    rezka4
    rezka5
    rezka6
    rezka7
    rezka8
    rezka9
  6. after send_to_CutFile

but if lines into files >1000 can see, what screen run after end send_to_CutFile;

i maked simple test event handler function :

static void event_handler(lv_obj_t * btn, lv_event_t event)

{

Serial.print("1. EVENT HANDLER, ");

if(event == LV_EVENT_CLICKED) {

            /*Increase the button width*/

        Serial.print("2.  CLICKED, ");   



        if (String(lv_list_get_btn_text(btn)) == "SETTINGS"){

                    Serial.print("3. SETTINGS, ");

                    lv_obj_t* scr;

                    lv_obj_t* label;

                    lv_obj_t* ok_btn;

                    scr = lv_obj_create(NULL, NULL); // create blank screen

                    ok_btn = lv_btn_create(scr, NULL);

                    //lv_obj_set_event_cb(ok_btn, event_handler);

                    lv_obj_align(ok_btn, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);

                    label = lv_label_create(ok_btn, NULL);

                    lv_label_set_text(label, "1 - Next");

                    lv_scr_load(scr);

                    int i=0;

                    for (i=0;i<5; i++ ) Serial.println(i);
        }

}

and recieved in com port:

1. EVENT HANDLER, 1. EVENT HANDLER, 1. EVENT HANDLER, 1. EVENT HANDLER, 1. EVENT HANDLER, 2.  CLICKED, 3. SETTINGS, 0
1
2
3
4
1. EVENT HANDLER,

why?

I could be missing something but that looks expected. Not every event is a CLICKED event, which is why you see 1. multiple times.

in program only one button with event handler with label SETTINGS

And I did not solve the problem with the load screen call - if change i in cycle for to i<3000, the screen will load only after the loop is completed.

why?