_lv_event_mark_deleted when closing msgbox

Description

hi, I have sometimes crash with _lv_event_mark_deleted when call lv_msgbox_close(lv_obj_t * msg) method.

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

ESP32-S3, PlatformIO

What LVGL version are you using?

LVGL version 8.3

What do you want to achieve?

I want to output errors from the queue in the form of msgbox with error information, but I have problems closing the msgbox.

What have you tried so far?

1.I’m tried replace lv_msgbox_close to lv_msgbox_close_async, but this not give result.
2. tried set mutex for lv_task_handler();

xGuiSemaphore = xSemaphoreCreateMutex();
void uiTask(void * ){
    draw.init();
    while(1){
        xSemaphoreTake(xGuiSemaphore, portMAX_DELAY);
        lv_task_handler();
        xSemaphoreGive(xGuiSemaphore);
        vTaskDelay(pdMS_TO_TICKS(10));
    }
}
  1. tried using mutex on closing msgbox with mutex in void uiTask(void * ), but with this it is impossible to close the tab
    xSemaphoreTake(xGuiSemaphore, portMAX_DELAY);
    lv_msgbox_close(msgbox);
    xSemaphoreGive(xGuiSemaphore);

4.tried check obj with lv_obj_is_valid before call lv_msgbox_close/lv_msgbox_close_async

Code to reproduce

The application must work with a touch screen and keyboard, and used commands for focus work.

EventGroupHandle_t errors_event;
static void msgbox_handler(lv_event_t * e){
    lv_group_focus_freeze(btn_group, false);
    if(on_msg == 1){ // current main tab on screen, 
        lv_group_focus_obj(exitBtn);
        lv_indev_set_group(keyboard_indev, main_menu_group);                
        on_msg = 0;   //unlock frequency convertors control
        lv_tabview_set_act(tv, 0, LV_ANIM_OFF);
    }else{          // if view menu focus to last element
        lv_group_focus_obj(focused);
    }
    lv_msgbox_close(msgbox);
    xEventGroupSetBits(errors_event, NEXT);  // allow create next msgbox
}

static bool messagebox_has_closed(){
    return xEventGroupWaitBits(errors_event, NEXT, pdTRUE, pdFALSE, portMAX_DELAY) & NEXT;
}

static const char * btns[] = {"OK", ""};
void errorsTask(void *){
    while(1){
        Error * error;
        if(messagebox_has_closed()){
            xQueueReceive(errors_queue, &error, portMAX_DELAY);
            focused = lv_group_get_focused(btn_group); //remember prev focused object
            
            if(tab_id == 0){  //main page
                on_msg = 1;   //set lock flag for control frequency convertors
            }
            lv_indev_set_group(keyboard_indev, btn_group);
            msgbox = lv_msgbox_create(NULL, error->getTitle(), error->getDescription(), btns, false);

            lv_obj_add_event_cb(msgbox, msgbox_handler, LV_EVENT_CLICKED,  NULL);

            lv_obj_set_size(msgbox, 350, 300);
            lv_obj_center(msgbox);
            lv_group_add_obj(btn_group, lv_msgbox_get_btns(msgbox));
            lv_group_focus_obj(lv_msgbox_get_btns(msgbox));
            lv_obj_add_state(lv_msgbox_get_btns(msgbox), LV_STATE_FOCUS_KEY);
            lv_group_focus_freeze(btn_group, true);
        } 
    }
}

I has changed LVGL to latest relise v8.3.11
Forget say, the msgbox goes to a layer above the tabview.
Simplified code for call error:

static const char * btns[] = {"OK", ""};
void errorsTask(void *){
    while(1){
        Error * error;
        xQueueReceive(errors_queue, &error, portMAX_DELAY);    
        msgbox = lv_msgbox_create(NULL, error->getTitle(), error->getDescription(), btns, true); 
        lv_obj_set_size(msgbox, 350, 300);
        lv_obj_center(msgbox);
    }
}

When I tap to close button on msgbox sometimes catch _lv_event_mark_deleted.

traceback:

#0 0x42013743:0x3fcecb80 in _lv_event_mark_deleted at lib/lvgl-8.3.11/src/core/lv_event.c:155
#1 0x4201652d:0x3fcecba0 in lv_obj_destructor at lib/lvgl-8.3.11/src/core/lv_obj.c:454
#2 0x420b42c3:0x3fcecbc0 in _lv_obj_destruct at lib/lvgl-8.3.11/src/core/lv_obj_class.c:136 (discriminator 1)
#3 0x4201b028:0x3fcecbe0 in obj_del_core at lib/lvgl-8.3.11/src/core/lv_obj_tree.c:385
(inlined by) obj_del_core at lib/lvgl-8.3.11/src/core/lv_obj_tree.c:351
#4 0x4201b064:0x3fcecc00 in obj_del_core at lib/lvgl-8.3.11/src/core/lv_obj_tree.c:362
#5 0x4201b064:0x3fcecc20 in obj_del_core at lib/lvgl-8.3.11/src/core/lv_obj_tree.c:362
#6 0x4201b132:0x3fcecc40 in lv_obj_del at lib/lvgl-8.3.11/src/core/lv_obj_tree.c:61
#7 0x42026b07:0x3fcecc60 in lv_msgbox_close at lib/lvgl-8.3.11/src/extra/widgets/msgbox/lv_msgbox.c:192
#8 0x42026b25:0x3fcecc80 in msgbox_close_click_event_cb at lib/lvgl-8.3.11/src/extra/widgets/msgbox/lv_msgbox.c:209

why is happened? maybe because of modal mode msgbox?

Solution, i’m used mutex uncorrect

void errorsTask(void *){
    Error * error;
    while(1){
        if(messagebox_has_closed()){
            xQueueReceive(errors_queue, &error, portMAX_DELAY);
            
            xSemaphoreTake(xGuiSemaphore, portMAX_DELAY);

            focused = lv_group_get_focused(btn_group); //remember prev focused object
            if(tab_id == 0){  //main page
               on_msg = 1;   //set lock flag for control frequency convertors
            }
            lv_indev_set_group(keyboard_indev, btn_group);
            msgbox = lv_msgbox_create(NULL, error->getTitle(), error->getDescription(), btns, true);
        
            lv_obj_add_event_cb(msgbox, msgbox_handler, LV_EVENT_CLICKED,  NULL);
            lv_obj_set_size(msgbox, 350, 300);
            lv_obj_center(msgbox);
            
            lv_group_add_obj(btn_group, lv_msgbox_get_btns(msgbox));
            lv_group_focus_obj(lv_msgbox_get_btns(msgbox));
            lv_obj_add_state(lv_msgbox_get_btns(msgbox), LV_STATE_FOCUS_KEY);
            lv_group_focus_freeze(btn_group, true);

            xSemaphoreGive(xGuiSemaphore);
        } 
    }
}