Godot Engine – Multi-platform 2D and 3D game engine
Fix potential crash in `TOOL_TOGGLE_SCENE_UNIQUE_NAME` tool selection.
Lukas Tenbrink8a9d19e067eb
diff --git a/editor/docks/scene_tree_dock.cpp b/editor/docks/scene_tree_dock.cppindex c9f712bfbf2..4cf1b3856aa 100644--- a/editor/docks/scene_tree_dock.cpp+++ b/editor/docks/scene_tree_dock.cpp@@ -1489,14 +1489,16 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {} break;case TOOL_TOGGLE_SCENE_UNIQUE_NAME: {// Enabling/disabling based on the same node based on which the checkbox in the menu is checked/unchecked.- const List<Node *>::Element *first_selected = editor_selection->get_top_selected_node_list().front();+ const List<Node *> selection = editor_selection->get_top_selected_node_list();+ Node *first_selected = selection.front() ? selection.front()->get() : nullptr;if (first_selected == nullptr) {return;}- if (first_selected->get() == EditorNode::get_singleton()->get_edited_scene()) {+ if (first_selected == EditorNode::get_singleton()->get_edited_scene()) {// Exclude Root Node. It should never be unique name in its own scene!- editor_selection->remove_node(first_selected->get());- first_selected = editor_selection->get_top_selected_node_list().front();+ editor_selection->remove_node(first_selected);+ const List<Node *> selection1 = editor_selection->get_top_selected_node_list();+ first_selected = selection1.front() ? selection1.front()->get() : nullptr;if (first_selected == nullptr) {return;}@@ -1518,7 +1520,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {return;}- bool enabling = !first_selected->get()->is_unique_name_in_owner();+ bool enabling = !first_selected->is_unique_name_in_owner();EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();