Browse Source

Fix crash in SceneTreeDock when closing a scene with a selected node

Aaron Franke 2 weeks ago
parent
commit
d492b665c3
3 changed files with 10 additions and 4 deletions
  1. 8 4
      editor/docks/scene_tree_dock.cpp
  2. 1 0
      editor/docks/scene_tree_dock.h
  3. 1 0
      editor/editor_node.cpp

+ 8 - 4
editor/docks/scene_tree_dock.cpp

@@ -2925,12 +2925,9 @@ void SceneTreeDock::_selection_changed() {
 	}
 
 	// Untrack script changes in previously selected nodes.
-	for (Node *node : node_previous_selection) {
-		node->disconnect(CoreStringName(script_changed), callable_mp(this, &SceneTreeDock::_queue_update_script_button));
-	}
+	clear_previous_node_selection();
 
 	// Track script changes in newly selected nodes.
-	node_previous_selection.clear();
 	node_previous_selection.reserve(editor_selection->get_selection().size());
 	for (const KeyValue<Node *, Object *> &E : editor_selection->get_selection()) {
 		Node *node = E.key;
@@ -3373,6 +3370,13 @@ static bool _is_same_selection(const Vector<Node *> &p_first, const List<Node *>
 	return true;
 }
 
+void SceneTreeDock::clear_previous_node_selection() {
+	for (Node *node : node_previous_selection) {
+		node->disconnect(CoreStringName(script_changed), callable_mp(this, &SceneTreeDock::_queue_update_script_button));
+	}
+	node_previous_selection.clear();
+}
+
 void SceneTreeDock::set_selection(const Vector<Node *> &p_nodes) {
 	// If the nodes selected are the same independently of order then return early.
 	if (_is_same_selection(p_nodes, editor_selection->get_full_selected_node_list())) {

+ 1 - 0
editor/docks/scene_tree_dock.h

@@ -324,6 +324,7 @@ public:
 	void set_edited_scene(Node *p_scene);
 	void instantiate(const String &p_file);
 	void instantiate_scenes(const Vector<String> &p_files, Node *p_parent = nullptr);
+	void clear_previous_node_selection();
 	void set_selection(const Vector<Node *> &p_nodes);
 	void set_selected(Node *p_node, bool p_emit_selected = false);
 	void fill_path_renames(Node *p_node, Node *p_new_parent, HashMap<Node *, NodePath> *p_renames);

+ 1 - 0
editor/editor_node.cpp

@@ -4248,6 +4248,7 @@ void EditorNode::_set_current_scene_nocheck(int p_idx) {
 	Node *old_scene = get_editor_data().get_edited_scene_root();
 
 	editor_selection->clear();
+	SceneTreeDock::get_singleton()->clear_previous_node_selection();
 	editor_data.set_edited_scene(p_idx);
 
 	Node *new_scene = editor_data.get_edited_scene_root();