Skip to content

Commit

Permalink
fix(obj) in lv_obj_move_to_index() do not send LV_EVENT_CHILD_CHANGED…
Browse files Browse the repository at this point in the history
… on all changed child

The events will see half-ready child list and might crash
fixes #2541
  • Loading branch information
kisvegabor committed Sep 9, 2021
1 parent 5ced080 commit 32e8276
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/core/lv_obj_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,26 +210,21 @@ void lv_obj_move_to_index(lv_obj_t * obj, int32_t index)
if(index == old_index) return;

int32_t i = old_index;
if(index < old_index)
{
while (i > index)
{
if(index < old_index) {
while (i > index) {
parent->spec_attr->children[i] = parent->spec_attr->children[i - 1];
lv_event_send(parent, LV_EVENT_CHILD_CHANGED, parent->spec_attr->children[i]);
i--;
}
}
else
{
while (i < index)
{
else {
while (i < index) {
parent->spec_attr->children[i] = parent->spec_attr->children[i + 1];
lv_event_send(parent, LV_EVENT_CHILD_CHANGED, parent->spec_attr->children[i]);
i++;
}
}

parent->spec_attr->children[index] = obj;
lv_event_send(parent, LV_EVENT_CHILD_CHANGED, obj);
lv_event_send(parent, LV_EVENT_CHILD_CHANGED, NULL);
lv_obj_invalidate(parent);
}

Expand Down

0 comments on commit 32e8276

Please sign in to comment.