How to lv_obj_clean list widget inside gridnav

Description

Hi, I want to use the list widget and navigate inside it using LV_KEY_UP and LV_KEY_DOWN only. So, I added the list widget to gridnav to achieve that. The problem is when I lv_obj_clean the list to delete the children of the list, the program crashes and output to the command line the following:


[Error] (207182.687, +828156)    lv_event_send: Asserted at expression: lv_obj_is_valid(obj) == true (The object is invalid, deleted or corrupted?)     (in lv_event.c line #56)

When I don’t use the gridnav, the lv_obj_clean() works perfectly.

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

PC Simulator for now.

What LVGL version are you using?

LVGL 8.3

What have you tried so far?

I tried to remove (lv_gridnav_remove(list)) it from the gridnav before I clean it, but it doesn’t work either.

Code to reproduce

static void eventHandler(lv_event_t* e) {

    uint32_t key = lv_event_get_key(e);

    if (key == LV_KEY_ENTER) {
        lv_obj_t* target = lv_event_get_target(e);
        lv_obj_t* parent = lv_obj_get_parent(target);
        lv_obj_clean(parent);
    }
}


void lv_listInsideGridnav() {

    lv_obj_t* list1 = lv_list_create(lv_scr_act());
    lv_obj_set_size(list1, lv_pct(45), lv_pct(80));
    lv_obj_set_style_radius(list1, 0, 0);
    lv_obj_align(list1, LV_ALIGN_LEFT_MID, 20, 0);

    lv_group_add_obj(lv_group_get_default(), list1);
    lv_gridnav_add(list1, LV_GRIDNAV_CTRL_NONE);  // when I remove this line it works

    lv_obj_t* item;
    char buff[6];
    
    for (int i = 0; i < 5; i++) {
        lv_snprintf(buff, 6, "Btn %d", i);
        item = lv_list_add_btn(list1, LV_SYMBOL_FILE, buff);
        lv_obj_add_event_cb(item, eventHandler, LV_EVENT_KEY, 0);
        lv_group_remove_obj(item);
    }

}

I tried again to remove the list from the gridnav and clean it (removing its children) and then add the list to gridnav again. IT WORKS!


static void eventHandler(lv_event_t* e) {

    uint32_t key = lv_event_get_key(e);

    if (key == LV_KEY_ENTER) {
        lv_obj_t* target = lv_event_get_target(e);
        lv_obj_t* parent = lv_obj_get_parent(target);
        // workaround
        lv_gridnav_remove(parent);
        lv_obj_clean(parent);
        lv_gridnav_add(parent, LV_GRIDNAV_CTRL_NONE);
    }
}

Thank you everyone,
Bader