Crashing in lv_msg_subsribe_obj- ESP32 T-RGB - Squareline project

I have a project that I created the UI in Squareline Studio adding logic from lilygo’s factory example to support the hardware. However, if I add a call to lv_msg_subscribe in my ui.c code, I get an immediate crash somewhere in that call.

With burn and crash debugging (I don’t have a debugger setup, just upload/moniotr through usb serial port), it’s been exceedingly slow tracing through the source to find out what’s crashing.

ui.h
====
#define MSG_BAT_VOLT_UPDATE       1
#define MSG_TOUCH_UPDATE          2
#define MSG_WIFI_UPDATE_OPTIONS   3
#define MSG_WIFI_UPDATE_TEXT      4
#define MSG_WIFI_MESSAGE          5

ui.ino
====

    Serial.println("no networks found");
    str = "no networks found";

    lv_msg_send(MSG_WIFI_UPDATE_TEXT, str.c_str());
    lv_msg_send(MSG_WIFI_UPDATE_OPTIONS, "");

ui.c
====

lv_obj_t * ui_ScreenWiFi_DropdownSSID;
void ui_event_ScreenWiFi_DropdownSSID(lv_event_t * e);

...

void ui_event_ScreenWiFi_DropdownSSID(lv_event_t * e)
{

    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t *dropdownSSID = (lv_obj_t *)lv_event_get_target(e);
    lv_msg_t *m = lv_event_get_msg(e);

    if (event_code == LV_EVENT_MSG_RECEIVED)
    {
        switch (lv_msg_get_id(m)) 
        {
            case MSG_WIFI_UPDATE_OPTIONS:
                lv_dropdown_set_options(dropdownSSID, lv_msg_get_payload(m));
                break;
            case MSG_WIFI_UPDATE_TEXT:
                lv_dropdown_set_text(dropdownSSID, lv_msg_get_payload(m));
                break;
            default:
                break;
        }
    }

}

...

void ui_init(void)
{
    lv_disp_t * dispp = lv_disp_get_default();
    lv_theme_t * theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
                                               false, LV_FONT_DEFAULT);
    lv_disp_set_theme(dispp, theme);
    ui_ScreenMain_screen_init();
    ui_ScreenSetup_screen_init();
    ui_ScreenWiFi_screen_init();
    lv_disp_load_scr(ui_ScreenMain);

    lv_obj_add_event_cb(ui_ScreenWiFi_DropdownSSID, ui_event_ScreenWiFi_DropdownSSID, LV_EVENT_MSG_RECEIVED, NULL);
    if (ui_ScreenWiFi_DropdownSSID != NULL)
    {
	
		// uncommenting either or both of these results in a crash that occurs somewhere in the lv_msg_subsribe_obj code
		
        //lv_msg_subsribe_obj(MSG_WIFI_UPDATE_OPTIONS, ui_ScreenWiFi_DropdownSSID, NULL);
        //lv_msg_subsribe_obj(MSG_WIFI_UPDATE_TEXT, ui_ScreenWiFi_DropdownSSID, NULL);    
		
    }

}

Here’s what I have… Any pointers on trying to debug this?

Fixed it, had to call lv_msg_init();

Documentation does not mention having to call lv_msg_init();

Calling this is vital and should be in the documentation. A flag in the code to bounce all the API calls if the init hasn’t been called would be extremely useful.

Hello Greg,

I am struggling with T-RGB as well to set it up for LVGL for work with Squareline Studio GUI. Could you help with advice how to set up lv_conf.h, *.ino and SLS project references?

Many thanks in advance for your help,
Thomas

The OP’s solution for their issue is not the correct way to fix the problem they were having. While it may work the way they did it the correct way is to enable messaging in lv_conf.h by setting the LV_USE_MSG macro to 1