From 2dadaaebad50994af2fdd28c8197eadd8d274e49 Mon Sep 17 00:00:00 2001 From: fuxiujun <1365570308@qq.com> Date: Thu, 30 Nov 2023 20:20:05 +0800 Subject: [PATCH] fix(tree): fix crash caused by clean parent in del cb (#4900) Signed-off-by: yushuailong1 Co-authored-by: yushuailong1 --- src/core/lv_obj_tree.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/core/lv_obj_tree.c b/src/core/lv_obj_tree.c index 7045336e9..47f3b9bf2 100644 --- a/src/core/lv_obj_tree.c +++ b/src/core/lv_obj_tree.c @@ -36,6 +36,7 @@ static void lv_obj_delete_async_cb(void * obj); static void obj_delete_core(lv_obj_t * obj); static lv_obj_tree_walk_res_t walk_core(lv_obj_t * obj, lv_obj_tree_walk_cb_t cb, void * user_data); static lv_obj_tree_walk_res_t dump_tree_core(lv_obj_t * obj, int32_t depth); +static lv_obj_t * lv_obj_get_first_not_deleting_child(lv_obj_t * obj); /********************** * STATIC VARIABLES @@ -99,10 +100,10 @@ void lv_obj_clean(lv_obj_t * obj) lv_obj_invalidate(obj); - lv_obj_t * child = lv_obj_get_child(obj, 0); + lv_obj_t * child = lv_obj_get_first_not_deleting_child(obj); while(child) { obj_delete_core(child); - child = lv_obj_get_child(obj, 0); + child = lv_obj_get_first_not_deleting_child(obj); } /*Just to remove scroll animations if any*/ lv_obj_scroll_to(obj, 0, 0, LV_ANIM_OFF); @@ -616,3 +617,20 @@ static lv_obj_tree_walk_res_t dump_tree_core(lv_obj_t * obj, int32_t depth) return LV_OBJ_TREE_WALK_END; } } + +static lv_obj_t * lv_obj_get_first_not_deleting_child(lv_obj_t * obj) +{ + LV_ASSERT_OBJ(obj, MY_CLASS); + + if(obj->spec_attr == NULL) return NULL; + + int32_t i; + int32_t cnt = (int32_t)obj->spec_attr->child_cnt; + for(i = 0; i < cnt; i++) { + if(!obj->spec_attr->children[i]->is_deleting) { + return obj->spec_attr->children[i]; + } + } + + return NULL; +} \ No newline at end of file