Pārlūkot izejas kodu

Merge pull request #67859 from timothyqiu/main-loop-tree

Fix crash of `queue_free()` when main loop is not SceneTree
Rémi Verschelde 2 gadi atpakaļ
vecāks
revīzija
7ef8583fc5
1 mainītis faili ar 5 papildinājumiem un 1 dzēšanām
  1. 5 1
      scene/main/node.cpp

+ 5 - 1
scene/main/node.cpp

@@ -2581,10 +2581,14 @@ void Node::print_orphan_nodes() {
 }
 
 void Node::queue_free() {
+	// There are users which instantiate multiple scene trees for their games.
+	// Use the node's own tree to handle its deletion when relevant.
 	if (is_inside_tree()) {
 		get_tree()->queue_delete(this);
 	} else {
-		SceneTree::get_singleton()->queue_delete(this);
+		SceneTree *tree = SceneTree::get_singleton();
+		ERR_FAIL_NULL_MSG(tree, "Can't queue free a node when no SceneTree is available.");
+		tree->queue_delete(this);
 	}
 }