From b06393747f61e36996a0cb22f9309c951f900ded Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 6 Jul 2021 13:49:33 +0200 Subject: [PATCH] fix(obj) move clean ups from lv_obj_del to lv_obj_destructor --- src/core/lv_obj.c | 15 ++++++++++++++- src/core/lv_obj_class.c | 6 +++--- src/core/lv_obj_class.h | 2 +- src/core/lv_obj_tree.c | 16 ++-------------- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/core/lv_obj.c b/src/core/lv_obj.c index e42bcec08..2d0221b80 100644 --- a/src/core/lv_obj.c +++ b/src/core/lv_obj.c @@ -401,6 +401,20 @@ static void lv_obj_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj) { LV_UNUSED(class_p); + _lv_event_mark_deleted(obj); + + /*Remove all style*/ + lv_obj_enable_style_refresh(false); /*No need to refresh the style because the object will be deleted*/ + lv_obj_remove_style_all(obj); + lv_obj_enable_style_refresh(true); + + /*Remove the animations from this object*/ + lv_anim_del(obj, NULL); + + /*Delete from the group*/ + lv_group_t * group = lv_obj_get_group(obj); + if(group) lv_group_remove_obj(obj); + if(obj->spec_attr) { if(obj->spec_attr->children) { lv_mem_free(obj->spec_attr->children); @@ -414,7 +428,6 @@ static void lv_obj_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj) lv_mem_free(obj->spec_attr); obj->spec_attr = NULL; } - } static void lv_obj_draw(lv_event_t * e) diff --git a/src/core/lv_obj_class.c b/src/core/lv_obj_class.c index cd39d1f1a..3837639ff 100644 --- a/src/core/lv_obj_class.c +++ b/src/core/lv_obj_class.c @@ -112,7 +112,6 @@ void lv_obj_class_init_obj(lv_obj_t * obj) lv_group_t * def_group = lv_group_get_default(); if(def_group && lv_obj_is_group_def(obj)) { - lv_group_add_obj(def_group, obj); } @@ -127,7 +126,7 @@ void lv_obj_class_init_obj(lv_obj_t * obj) } } -void _lv_obj_destructor(lv_obj_t * obj) +void _lv_obj_destruct(lv_obj_t * obj) { if(obj->class_p->destructor_cb) obj->class_p->destructor_cb(obj->class_p, obj); @@ -136,7 +135,7 @@ void _lv_obj_destructor(lv_obj_t * obj) obj->class_p = obj->class_p->base_class; /*Call the base class's destructor too*/ - _lv_obj_destructor(obj); + _lv_obj_destruct(obj); } } @@ -163,6 +162,7 @@ bool lv_obj_is_group_def(lv_obj_t * obj) return class_p->group_def == LV_OBJ_CLASS_GROUP_DEF_TRUE ? true : false; } + /********************** * STATIC FUNCTIONS **********************/ diff --git a/src/core/lv_obj_class.h b/src/core/lv_obj_class.h index a2ddd1638..0bf0dad59 100644 --- a/src/core/lv_obj_class.h +++ b/src/core/lv_obj_class.h @@ -75,7 +75,7 @@ struct _lv_obj_t * lv_obj_class_create_obj(const struct _lv_obj_class_t * class_ void lv_obj_class_init_obj(struct _lv_obj_t * obj); -void _lv_obj_destructor(struct _lv_obj_t * obj); +void _lv_obj_destruct(struct _lv_obj_t * obj); bool lv_obj_is_editable(struct _lv_obj_t * obj); diff --git a/src/core/lv_obj_tree.c b/src/core/lv_obj_tree.c index ab9bfe3ae..a8e424890 100644 --- a/src/core/lv_obj_tree.c +++ b/src/core/lv_obj_tree.c @@ -343,13 +343,6 @@ static void obj_del_core(lv_obj_t * obj) lv_res_t res = lv_event_send(obj, LV_EVENT_DELETE, NULL); if(res == LV_RES_INV) return; - /*Delete from the group*/ - lv_group_t * group = lv_obj_get_group(obj); - if(group) lv_group_remove_obj(obj); - - /*Remove the animations from this object*/ - lv_anim_del(obj, NULL); - /*Recursively delete the children*/ lv_obj_t * child = lv_obj_get_child(obj, 0); while(child) { @@ -357,12 +350,7 @@ static void obj_del_core(lv_obj_t * obj) child = lv_obj_get_child(obj, 0); } - _lv_event_mark_deleted(obj); - - /*Remove all style*/ - lv_obj_enable_style_refresh(false); /*No need to refresh the style because the object will be deleted*/ - lv_obj_remove_style_all(obj); - lv_obj_enable_style_refresh(true); + lv_group_t * group = lv_obj_get_group(obj); /*Reset all input devices if the object to delete is used*/ lv_indev_t * indev = lv_indev_get_next(NULL); @@ -381,7 +369,7 @@ static void obj_del_core(lv_obj_t * obj) } /*All children deleted. Now clean up the object specific data*/ - _lv_obj_destructor(obj); + _lv_obj_destruct(obj); /*Remove the screen for the screen list*/ if(obj->parent == NULL) {