Skip to content

Commit

Permalink
Merge pull request godotengine#90266 from akien-mga/scenetreeeditor-f…
Browse files Browse the repository at this point in the history
…ix-treeitem-crash

SceneTreeEditor: Fix crash when TreeItem is removed before callback
  • Loading branch information
akien-mga committed Apr 5, 2024
2 parents c493217 + 6b8daa4 commit 655e93d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion editor/gui/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,14 @@ void SceneTreeEditor::_cell_multi_selected(Object *p_object, int p_cell, bool p_
}
}

void SceneTreeEditor::_tree_scroll_to_item(ObjectID p_item_id) {
ERR_FAIL_NULL(tree);
TreeItem *item = Object::cast_to<TreeItem>(ObjectDB::get_instance(p_item_id));
if (item) {
tree->scroll_to_item(item, true);
}
}

void SceneTreeEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
Expand Down Expand Up @@ -942,7 +950,8 @@ void SceneTreeEditor::_notification(int p_what) {

if (item) {
// Must wait until tree is properly sized before scrolling.
callable_mp(tree, &Tree::scroll_to_item).call_deferred(item, true);
ObjectID item_id = item->get_instance_id();
callable_mp(this, &SceneTreeEditor::_tree_scroll_to_item).call_deferred(item_id);
}
}
} break;
Expand Down
1 change: 1 addition & 0 deletions editor/gui/scene_tree_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class SceneTreeEditor : public Control {
void _set_item_custom_color(TreeItem *p_item, Color p_color);
void _update_node_tooltip(Node *p_node, TreeItem *p_item);
void _queue_update_node_tooltip(Node *p_node, TreeItem *p_item);
void _tree_scroll_to_item(ObjectID p_item_id);

void _selection_changed();
Node *get_scene_node() const;
Expand Down

0 comments on commit 655e93d

Please sign in to comment.