1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

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 <pengyiqiang@xiaomi.com>
This commit is contained in:
_VIFEXTech 2022-08-19 20:24:37 +08:00 committed by GitHub
parent 778d872409
commit bb7feb232f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -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;

View File

@ -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);
}