Skip to content

Commit

Permalink
Merge pull request #88943 from lawnjelly/fix_scenedock_filter_crash
Browse files Browse the repository at this point in the history
[3.x] Fix SceneTree dock filter crash
  • Loading branch information
akien-mga authored Feb 28, 2024
2 parents 6e0468d + 39e61b7 commit 60ff43b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions editor/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,16 @@ bool SceneTreeEditor::_update_filter(TreeItem *p_parent, bool p_scroll_to_select
}

bool keep_for_children = false;

// Get the list of children ahead of time, as the list may be invalidated by deleting one of them.
LocalVector<TreeItem *> children;
for (TreeItem *child = p_parent->get_children(); child; child = child->get_next()) {
children.push_back(child);
}

for (uint32_t n = 0; n < children.size(); n++) {
// Always keep if at least one of the children are kept.
keep_for_children = _update_filter(child, p_scroll_to_selected) || keep_for_children;
keep_for_children = _update_filter(children[n], p_scroll_to_selected) || keep_for_children;
}

// Now find other reasons to keep this Node, too.
Expand All @@ -617,8 +624,6 @@ bool SceneTreeEditor::_update_filter(TreeItem *p_parent, bool p_scroll_to_select
}
}
}
} else {
memdelete(p_parent);
}

if (editor_selection) {
Expand All @@ -635,6 +640,10 @@ bool SceneTreeEditor::_update_filter(TreeItem *p_parent, bool p_scroll_to_select
}
}

if (!(keep || keep_for_children)) {
memdelete(p_parent);
}

return keep || keep_for_children;
}

Expand Down

0 comments on commit 60ff43b

Please sign in to comment.