Description
Try to implement an app with multiple screens.
Before drawing the new screen i need to clean the content.
Tried both ways:
cleaning entire active screen using lv_obj_clean(lv_scr_act());
cleaning object by object using lv_obj_clean(object);
both cases it crashes mostly in lv_object_tree.c/lv_obj_clean(lv_obj_t * obj) and sometimes in lv_timer_handler()
Here is the full call stack at crash time
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400eb81a PS : 0x00060e30 A0 : 0x800ec8d0 A1 : 0x3fff8f50
0x400eb81a: _lv_event_mark_deleted at C:/dev/esp32/esp32wp_controller/managed_components/lvgl__lvgl/src/core/lv_event.c:156
A2 : 0x3ffb6940 A3 : 0x3ffb6b94 A4 : 0x0000000c A5 : 0x3ffb6940
A6 : 0x00000000 A7 : 0xff000000 A8 : 0x00000001 A9 : 0x00000000
A10 : 0x3ffb5000 A11 : 0x3ffb6b94 A12 : 0x3ffb6ba4 A13 : 0x00000000
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x0000001d EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000005 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff
0x4000c2e0: memcpy in ROM
0x4000c2f6: memcpy in ROM
Backtrace: 0x400eb817:0x3fff8f50 0x400ec8cd:0x3fff8f70 0x401b20a3:0x3fff8f90 0x401b20b1:0x3fff8fb0 0x400f1738:0x3fff8fd0 0x400f183c:0x3fff8ff0 0x400dc02c:0x3fff9010 0x400db674:0x3fff9080 0x4008f18e:0x3fff90a0
0x400eb817: _lv_event_mark_deleted at C:/dev/esp32/esp32wp_controller/managed_components/lvgl__lvgl/src/core/lv_event.c:155
0x400ec8cd: lv_obj_destructor at C:/dev/esp32/esp32wp_controller/managed_components/lvgl__lvgl/src/core/lv_obj.c:454
0x401b20a3: _lv_obj_destruct at C:/dev/esp32/esp32wp_controller/managed_components/lvgl__lvgl/src/core/lv_obj_class.c:136 (discriminator 1)
0x401b20b1: _lv_obj_destruct at C:/dev/esp32/esp32wp_controller/managed_components/lvgl__lvgl/src/core/lv_obj_class.c:143
0x400f1738: obj_del_core at C:/dev/esp32/esp32wp_controller/managed_components/lvgl__lvgl/src/core/lv_obj_tree.c:385
0x400f183c: lv_obj_clean at C:/dev/esp32/esp32wp_controller/managed_components/lvgl__lvgl/src/core/lv_obj_tree.c:89
0x400dc02c: do_main_screen at C:/dev/esp32/esp32wp_controller/lcd/main_screen.c:223
0x400db674: ui_task at C:/dev/esp32/esp32wp_controller/lcd/lcd.c:146
0x4008f18e: vPortTaskWrapper at C:/dev/esp32/esp-idf-v5.1.2/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162
**0x400db674: ui_task at C:/dev/esp32/esp32wp_controller/lcd/lcd.c:146** above is my function calling lv_obj_clean()
and here is the code for one of my screens.
static void draw_main_screen(lv_disp_t *disp, int active_screen)
{
lv_obj_t *label;
gpio_set_level(LCD_BK_LIGHT, LCD_BK_LIGHT_OFF_LEVEL);
lv_obj_clean(lv_scr_act());
lv_style_init(&watch_style);
lv_style_set_text_color(&watch_style, lv_color_hex(0xc0c0c0));
lv_style_set_text_font(&watch_style, &seg_black_40);
btns[0].btn = lv_btn_create(lv_scr_act());
lv_obj_add_style(btns[0].btn, &btn_norm, 0);
lv_obj_add_style(btns[0].btn, &btn_sel, LV_STATE_PRESSED);
lv_obj_set_pos(btns[0].btn, 60, 90);
lv_obj_set_size(btns[0].btn, 200, 45);
lv_obj_add_event_cb(btns[0].btn, bpump_event_cb, LV_EVENT_ALL, NULL);
label = lv_label_create(btns[0].btn);
lv_label_set_text(label, "Pump");
lv_obj_center(label);
lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0);
btns[0].state = 0;
lv_obj_t * ledp = lv_led_create(btns[0].btn);
lv_obj_align(ledp, LV_ALIGN_RIGHT_MID, 0, 0);
lv_led_set_brightness(ledp, 255);
lv_led_set_color(ledp, lv_color_hex(0xc0c0c0));
btns[1].btn = lv_btn_create(lv_scr_act());
lv_obj_add_style(btns[1].btn, &btn_norm, 0);
lv_obj_add_style(btns[1].btn, &btn_sel, LV_STATE_PRESSED);
lv_obj_set_pos(btns[1].btn, 60, 160);
lv_obj_set_size(btns[1].btn, 200, 45);
lv_obj_add_event_cb(btns[1].btn, bwater_event_cb, LV_EVENT_ALL, NULL);
label = lv_label_create(btns[1].btn);
lv_label_set_text(label, "Watering");
lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0);
lv_obj_t * ledw = lv_led_create(btns[1].btn);
lv_obj_align(ledw, LV_ALIGN_RIGHT_MID, 0, 0);
lv_led_set_brightness(ledw, 255);
lv_led_set_color(ledw, lv_color_hex(0xc0c0c0));
btns[1].state = 1;
if(active_screen == PUMP_SCREEN)
lv_obj_add_state(btns[0].btn, LV_STATE_PRESSED);
if(active_screen == WATER_SCREEN)
lv_obj_add_state(btns[1].btn, LV_STATE_PRESSED);
watch = lv_label_create(lv_scr_act());
lv_obj_set_pos(watch, 10, 10);
lv_obj_set_size(watch, 290, 60);
lv_obj_add_style(watch, &watch_style, 0);
time_t now = 0;
char buf[24];
struct tm timeinfo = { 0 };
time(&now);
localtime_r(&now, &timeinfo);
sprintf(buf, "%02d:%02d - %02d.%02d", timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_mday, (timeinfo.tm_mon + 1));
lv_label_set_text(watch, buf);
gpio_set_level(LCD_BK_LIGHT, LCD_BK_LIGHT_ON_LEVEL);
}
If i comment out **lv_obj_clean(lv_scr_act())**, no crash but the content is overwritten.
Sometimes the crash show up after few transitions between screens, sometimes immediately.
As i'm new to lvgl i just took the app template provided in esp examples and try to adapt it to my application.
Are there any restrictions using lv_object_clean() function?
What MCU/Processor/Board and compiler are you using?
ESP32-WROOM32 ESP_IDF v5.1.2
What LVGL version are you using?
8.3.11