Skip to content

Commit

Permalink
fix(obj) move clean ups from lv_obj_del to lv_obj_destructor
Browse files Browse the repository at this point in the history
  • Loading branch information
kisvegabor committed Jul 6, 2021
1 parent 45eda2f commit b063937
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
15 changes: 14 additions & 1 deletion src/core/lv_obj.c
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/core/lv_obj_class.c
Expand Up @@ -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);
}

Expand All @@ -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);

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

Expand All @@ -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
**********************/
Expand Down
2 changes: 1 addition & 1 deletion src/core/lv_obj_class.h
Expand Up @@ -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);

Expand Down
16 changes: 2 additions & 14 deletions src/core/lv_obj_tree.c
Expand Up @@ -343,26 +343,14 @@ 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) {
obj_del_core(child);
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);
Expand All @@ -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) {
Expand Down

0 comments on commit b063937

Please sign in to comment.