Best way to create and delete objects


Hello i’m new to lvgl and i’m now studying it.
I have a button that when clicked create/delete a list in the main window.

It works the first time creating the list, it works deleting it, but it crashes the ESP32 and reboot it if i try again to create it

What i’m doing wrong? what is the best way to do this?

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

ESP32 with ILI9341 on platformio.

What LVGL version are you using?


What do you want to achieve?

Create and remove objects based on events.

What have you tried so far?

with the same result

Code to reproduce

static void setting_event_cb(lv_obj_t *obj, lv_event_t event) {
  // Serial.println("CLICK!!!!");
  if (event == LV_EVENT_CLICKED) {
    if (!lista) {
      lista = lv_list_create(main_window, NULL);
      lv_obj_set_width(lista, 160);
      lv_obj_align(lista, NULL, LV_ALIGN_CENTER, 0, 0);
      pulsanti = lv_list_add_btn(lista, LV_SYMBOL_SETTINGS, "Settings");
      lv_obj_set_event_cb(pulsanti, event_handler);
      pulsanti = lv_list_add_btn(lista, LV_SYMBOL_WIFI, "Wifi");
      lv_obj_set_event_cb(pulsanti, event_handler);


Guru Meditation Error: Core 0 panic’ed (IllegalInstruction). Exception was unhandled.
Core 0 register dump:
PC : 0x5500ff77 PS : 0x00060a30 A0 : 0x800d4326 A1 : 0x3ffb3d70
A2 : 0x5500ff77 A3 : 0x00000000 A4 : 0x00000015 A5 : 0x3ffb3d84
A6 : 0x3ffc3c7c A7 : 0x3ffc51b8 A8 : 0x800d42c9 A9 : 0x00000000
A10 : 0x3ffc51b8 A11 : 0x00000015 A12 : 0x00000000 A13 : 0x3ffc3ebc
A14 : 0x00000001 A15 : 0x00000002 SAR : 0x0000000b EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000 LBEG : 0x401070e4 LEND : 0x401070ee LCOUNT : 0x00000000

ELF file SHA256: 0000000000000000

Backtrace: 0x5500ff77:0x3ffb3d70 0x400d4323:0x3ffb3db0 0x400d629b:0x3ffb3dd0 0x400d63a7:0x3ffb3df0 0x400d1666:0x3ffb3e10 0x400d42c6:0x3ffb3e30 0x400d4323:0x3ffb3e70 0x400e88f3:0x3ffb3e90 0x400e9228:0x3ffb3eb0 0x400e0457:0x3ffb3f00 0x400e0535:0x3ffb3f20 0x400d1803:0x3ffb3f50 0x40086366:0x3ffb3fe0

ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
mode:DIO, clock div:2
entry 0x400806a8

OK i solved hidding and showing the list like this, i don’t know if this is the best way, i hope to hear from experts.

Thank you

void setting_event_cb(lv_obj_t *obj, lv_event_t event) {
  if (event == LV_EVENT_CLICKED) {
    if (lv_obj_get_hidden(lista)) {
      lv_obj_set_hidden(lista, false);
    } else{
      lv_obj_set_hidden(lista, true);

Another update, i solved by adding lista = NULL; after deleting it.

This is the correct solution. Your original problem was that you tried to delete an already-deleted list. With C, you unfortunately have to remember to set object references to NULL after you delete them if you wish to check for their existence later.