Skip to content

Commit 6b8daa4

Browse files
akien-mgabruvzg
andcommitted
SceneTreeEditor: Fix crash when TreeItem is removed before callback
Fixes godotengine#90235. Co-authored-by: bruvzg <[email protected]>
1 parent 7e4c150 commit 6b8daa4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

editor/gui/scene_tree_editor.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,14 @@ void SceneTreeEditor::_cell_multi_selected(Object *p_object, int p_cell, bool p_
897897
}
898898
}
899899

900+
void SceneTreeEditor::_tree_scroll_to_item(ObjectID p_item_id) {
901+
ERR_FAIL_NULL(tree);
902+
TreeItem *item = Object::cast_to<TreeItem>(ObjectDB::get_instance(p_item_id));
903+
if (item) {
904+
tree->scroll_to_item(item, true);
905+
}
906+
}
907+
900908
void SceneTreeEditor::_notification(int p_what) {
901909
switch (p_what) {
902910
case NOTIFICATION_ENTER_TREE: {
@@ -942,7 +950,8 @@ void SceneTreeEditor::_notification(int p_what) {
942950

943951
if (item) {
944952
// Must wait until tree is properly sized before scrolling.
945-
callable_mp(tree, &Tree::scroll_to_item).call_deferred(item, true);
953+
ObjectID item_id = item->get_instance_id();
954+
callable_mp(this, &SceneTreeEditor::_tree_scroll_to_item).call_deferred(item_id);
946955
}
947956
}
948957
} break;

editor/gui/scene_tree_editor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class SceneTreeEditor : public Control {
123123
void _set_item_custom_color(TreeItem *p_item, Color p_color);
124124
void _update_node_tooltip(Node *p_node, TreeItem *p_item);
125125
void _queue_update_node_tooltip(Node *p_node, TreeItem *p_item);
126+
void _tree_scroll_to_item(ObjectID p_item_id);
126127

127128
void _selection_changed();
128129
Node *get_scene_node() const;

0 commit comments

Comments
 (0)