mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
fix(obj): fix the crash caused by nested calls to lv_obj_del (#4520)
Signed-off-by: YanXiaowei <yanxiaowei@xiaomi.com> Co-authored-by: YanXiaowei <yanxiaowei@xiaomi.com>
This commit is contained in:
parent
af959cb94e
commit
a1ba36b77c
@ -194,6 +194,7 @@ typedef struct _lv_obj_t {
|
||||
uint16_t style_cnt : 6;
|
||||
uint16_t h_layout : 1;
|
||||
uint16_t w_layout : 1;
|
||||
uint16_t is_deleting : 1;
|
||||
} lv_obj_t;
|
||||
|
||||
/**********************
|
||||
|
@ -48,12 +48,15 @@ static lv_obj_tree_walk_res_t walk_core(lv_obj_t * obj, lv_obj_tree_walk_cb_t cb
|
||||
|
||||
void lv_obj_del(lv_obj_t * obj)
|
||||
{
|
||||
if(obj->is_deleting)
|
||||
return;
|
||||
|
||||
LV_LOG_TRACE("begin (delete %p)", (void *)obj);
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_obj_invalidate(obj);
|
||||
|
||||
lv_obj_t * par = lv_obj_get_parent(obj);
|
||||
if(par) {
|
||||
if(par && !par->is_deleting) {
|
||||
lv_obj_scrollbar_invalidate(par);
|
||||
}
|
||||
|
||||
@ -68,7 +71,7 @@ void lv_obj_del(lv_obj_t * obj)
|
||||
obj_del_core(obj);
|
||||
|
||||
/*Call the ancestor's event handler to the parent to notify it about the child delete*/
|
||||
if(par) {
|
||||
if(par && !par->is_deleting) {
|
||||
lv_obj_update_layout(par);
|
||||
lv_obj_readjust_scroll(par, LV_ANIM_OFF);
|
||||
lv_obj_scrollbar_invalidate(par);
|
||||
@ -373,6 +376,14 @@ static void obj_del_core(lv_obj_t * obj)
|
||||
lv_res_t res = lv_obj_send_event(obj, LV_EVENT_DELETE, NULL);
|
||||
if(res == LV_RES_INV) return;
|
||||
|
||||
obj->is_deleting = true;
|
||||
|
||||
/*Clean registered event_cb*/
|
||||
uint32_t event_cnt = lv_obj_get_event_count(obj);
|
||||
for(uint32_t i = 0; i < event_cnt; i++) {
|
||||
lv_obj_remove_event(obj, i);
|
||||
}
|
||||
|
||||
/*Recursively delete the children*/
|
||||
lv_obj_t * child = lv_obj_get_child(obj, 0);
|
||||
while(child) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user