From bb7feb232fbe41e03cefe52b9884d1a6110d5a91 Mon Sep 17 00:00:00 2001 From: _VIFEXTech <1290176185@qq.com> Date: Fri, 19 Aug 2022 20:24:37 +0800 Subject: [PATCH] fix(obj): fix crash of lv_obj_move_foreground/background when the parent of obj is NULL (#3577) * fix(obj): fix crash of lv_obj_move_foreground/background when the parent of obj is NULL * decrease LOG level Co-authored-by: pengyiqiang --- src/core/lv_obj_tree.c | 11 ++++++++--- src/lv_api_map.h | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/core/lv_obj_tree.c b/src/core/lv_obj_tree.c index 446d0dc68..4b1bd06e6 100644 --- a/src/core/lv_obj_tree.c +++ b/src/core/lv_obj_tree.c @@ -191,14 +191,19 @@ void lv_obj_move_to_index(lv_obj_t * obj, int32_t index) { LV_ASSERT_OBJ(obj, MY_CLASS); + lv_obj_t * parent = lv_obj_get_parent(obj); + + if(!parent) { + LV_LOG_WARN("parent is NULL"); + return; + } + if(index < 0) { - index = lv_obj_get_child_cnt(lv_obj_get_parent(obj)) + index; + index = lv_obj_get_child_cnt(parent) + index; } const int32_t old_index = lv_obj_get_index(obj); - lv_obj_t * parent = lv_obj_get_parent(obj); - if(index < 0) return; if(index >= (int32_t) lv_obj_get_child_cnt(parent)) return; if(index == old_index) return; diff --git a/src/lv_api_map.h b/src/lv_api_map.h index f2b640a4a..e11f77df2 100644 --- a/src/lv_api_map.h +++ b/src/lv_api_map.h @@ -55,6 +55,11 @@ static inline LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_task_handler(void) static inline void lv_obj_move_foreground(lv_obj_t * obj) { lv_obj_t * parent = lv_obj_get_parent(obj); + if(!parent) { + LV_LOG_WARN("parent is NULL"); + return; + } + lv_obj_move_to_index(obj, lv_obj_get_child_cnt(parent) - 1); }