From 6b8daa498e2e31edec4b89e0c5321cef7bb51be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Fri, 5 Apr 2024 16:51:54 +0200 Subject: [PATCH] SceneTreeEditor: Fix crash when TreeItem is removed before callback Fixes #90235. Co-authored-by: bruvzg <7645683+bruvzg@users.noreply.github.com> --- editor/gui/scene_tree_editor.cpp | 11 ++++++++++- editor/gui/scene_tree_editor.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp index 0dd75ea03351..221061f9f7f2 100644 --- a/editor/gui/scene_tree_editor.cpp +++ b/editor/gui/scene_tree_editor.cpp @@ -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(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: { @@ -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; diff --git a/editor/gui/scene_tree_editor.h b/editor/gui/scene_tree_editor.h index c1abdcef8b0c..b4d9644f167a 100644 --- a/editor/gui/scene_tree_editor.h +++ b/editor/gui/scene_tree_editor.h @@ -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;