_lv_event_mark_deleted crashes sometimes


i build a c++ Applicaion with a lvgl GUI, which shows me errors and data of devices. The Data and Errors are received over a messageBus. An sometimes i close a MessageBox the Application crashes in _lv_event_mark_deleted Function.

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

I use the SDL Simulator on a Ubuntu 20.04 VirtualMachine and a i.MX 6 board with the GCC-Compiler.

What LVGL version are you using?

Tried with 8.0, 8.2 and 8.3.

What do you want to achieve?

I would like to Show a MessageBox every Time an Error occurs from the messageBus. This is works fine.

If the Error disapears (event from the messageBus) the MessageBox should be closed. Here is the Problem. Sometimes, when the MessageBox is closed, my Application crashes in the _lv_event_mark_deleted Function.

What have you tried so far?

I tried to use different widgets

  • the lv_msgbox (modal / non Modal)
  • self created MessageBox based on lv_obj

I tried to use different screens and different layers (top/sys layer)
I tried to use lv_obj_del_async and lv_obj_del

I tried to debug with enabling the Log-Messages (LV_LOG_...)

Code to reproduce

I wrote a Wrapper Class for all lv_obj that were created. This class has an destroy Method to delete the lvgl object. I use the lv_obj_is_valid Method to check, that a Object is valid to delete.

The Method shows the synchron way for the Deletion. In this case the code crashes in the line with lv_obj_del(m_widget);

void BaseLvglWidget::destroyLvWidget()
    if(m_widget and (not m_isDeleted) and lv_obj_is_valid(m_widget))
        m_isEnabled = false; // Block Signal publishs
        m_isDeleted = true;   // Avoid using the Object after Deletion

In the Async Method the Crash is during the run of the lv_timer_handler

Screenshot and/or video

Can someone help me or guide me in the right direction to solve the Problem?

Is the application multi thread? If so use mutex to make sure your not changing anything when lv task handler runs

1 Like

I got basically the same issue. It occurs rather randomly.

Hi, yes the Applikation is multi threaded. I will try tomorrow to use a mutex.
Thanks for your reply.

That worked for me. Great.
Thank you very much !!

Hi, @cmmderPg could you please elaborate on where you used mutex. I was debugging through the GDB compiler and a segmentation fault occured at _lv_event_mark_deleted function when I used lv_obj_clean function(similar to lv_obj_del).

Hi Dave,
i have a globally accessible recursive_mutex and call the lock every Time before i call a lv_.... function or a block of lv... functions.

Defined Mutex:
std::recursive_mutex LV_Mutex

Using Example:

        const std::lock_guard<std::recursive_mutex> lock(m_frontend.LV_Mutex);
        lv_obj_clear_flag(m_widget, LV_OBJ_FLAG_SCROLLABLE);
        lv_obj_clear_flag(m_widget, LV_OBJ_FLAG_PRESS_LOCK);
        lv_obj_add_event_cb(m_widget, jmpEvent, filter, this);

You have to be sure that each lv_... call is protected by a lock.

Sure thanks for your response. I will have a look into it and update you on what happens.

@cmmderPg Do I also have to mutex lock where lv_task_handler or lv_timer_handler is called?

Yes, really on every place where you call a lv_ Function.

1 Like

Won’t that remove the entire purpose of multi-threading as my mutex will always be busy in running the lvgl thread.

I do not think so. In my case the call of lv_timer_handler looks like follows, and the multi-threading works fine.

    while(not m_stop)
            const std::lock_guard<std::recursive_mutex> lock(m_frontend.LV_Mutex);
            runAgain = lv_timer_handler();

1 Like