Skip to content

Commit 2bfc321

Browse files
committed
Merge pull request #108883 from aaronfranke/editor-crash-scene-tree-dock
Fix crash in SceneTreeDock when closing a scene with a selected node
2 parents b005559 + d492b66 commit 2bfc321

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

editor/docks/scene_tree_dock.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,12 +2930,9 @@ void SceneTreeDock::_selection_changed() {
29302930
}
29312931

29322932
// Untrack script changes in previously selected nodes.
2933-
for (Node *node : node_previous_selection) {
2934-
node->disconnect(CoreStringName(script_changed), callable_mp(this, &SceneTreeDock::_queue_update_script_button));
2935-
}
2933+
clear_previous_node_selection();
29362934

29372935
// Track script changes in newly selected nodes.
2938-
node_previous_selection.clear();
29392936
node_previous_selection.reserve(editor_selection->get_selection().size());
29402937
for (const KeyValue<Node *, Object *> &E : editor_selection->get_selection()) {
29412938
Node *node = E.key;
@@ -3378,6 +3375,13 @@ static bool _is_same_selection(const Vector<Node *> &p_first, const List<Node *>
33783375
return true;
33793376
}
33803377

3378+
void SceneTreeDock::clear_previous_node_selection() {
3379+
for (Node *node : node_previous_selection) {
3380+
node->disconnect(CoreStringName(script_changed), callable_mp(this, &SceneTreeDock::_queue_update_script_button));
3381+
}
3382+
node_previous_selection.clear();
3383+
}
3384+
33813385
void SceneTreeDock::set_selection(const Vector<Node *> &p_nodes) {
33823386
// If the nodes selected are the same independently of order then return early.
33833387
if (_is_same_selection(p_nodes, editor_selection->get_full_selected_node_list())) {

editor/docks/scene_tree_dock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ class SceneTreeDock : public VBoxContainer {
324324
void set_edited_scene(Node *p_scene);
325325
void instantiate(const String &p_file);
326326
void instantiate_scenes(const Vector<String> &p_files, Node *p_parent = nullptr);
327+
void clear_previous_node_selection();
327328
void set_selection(const Vector<Node *> &p_nodes);
328329
void set_selected(Node *p_node, bool p_emit_selected = false);
329330
void fill_path_renames(Node *p_node, Node *p_new_parent, HashMap<Node *, NodePath> *p_renames);

editor/editor_node.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4248,6 +4248,7 @@ void EditorNode::_set_current_scene_nocheck(int p_idx) {
42484248
Node *old_scene = get_editor_data().get_edited_scene_root();
42494249

42504250
editor_selection->clear();
4251+
SceneTreeDock::get_singleton()->clear_previous_node_selection();
42514252
editor_data.set_edited_scene(p_idx);
42524253

42534254
Node *new_scene = editor_data.get_edited_scene_root();

0 commit comments

Comments
 (0)