Quellcode durchsuchen

fix releasing the old unique name when renaming a Node

This fixes `Node::set_name()` to release the old unique name before
performing the rename.  #76560 changed the code to update `data.name`
before calling `_release_unique_name_in_owner()`, causing to incorrectly
try releasing the new name instead of the old name.

Fixes #108683
Adam Simpkins vor 2 Wochen
Ursprung
Commit
254fa6c642
1 geänderte Dateien mit 6 neuen und 5 gelöschten Zeilen
  1. 6 5
      scene/main/node.cpp

+ 6 - 5
scene/main/node.cpp

@@ -1416,10 +1416,15 @@ void Node::_set_name_nocheck(const StringName &p_name) {
 
 void Node::set_name(const StringName &p_name) {
 	ERR_FAIL_COND_MSG(data.tree && !Thread::is_main_thread(), "Changing the name to nodes inside the SceneTree is only allowed from the main thread. Use `set_name.call_deferred(new_name)`.");
+	ERR_FAIL_COND(p_name.is_empty());
+
 	const StringName old_name = data.name;
+	if (data.unique_name_in_owner && data.owner) {
+		_release_unique_name_in_owner();
+	}
+
 	{
 		const String input_name_str = String(p_name);
-		ERR_FAIL_COND(input_name_str.is_empty());
 		const String validated_node_name_string = input_name_str.validate_node_name();
 		if (input_name_str == validated_node_name_string) {
 			data.name = p_name;
@@ -1428,10 +1433,6 @@ void Node::set_name(const StringName &p_name) {
 		}
 	}
 
-	if (data.unique_name_in_owner && data.owner) {
-		_release_unique_name_in_owner();
-	}
-
 	if (data.parent) {
 		data.parent->_validate_child_name(this, true);
 		bool success = data.parent->data.children.replace_key(old_name, data.name);