diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-11-15 10:27:17 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-11-15 10:27:17 +0100 |
commit | 7ef8583fc58a08d4b058efa0c21421071f6f6b92 (patch) | |
tree | 9d61208dba8cf250578e7ad5b475ba3ab0782a79 | |
parent | 98e0d599529aee2b090d84acbd9aaa28572c0da8 (diff) | |
parent | 3b08d0e85233a594b016ae27e06b5f21536a6176 (diff) |
Merge pull request #67859 from timothyqiu/main-loop-tree
Fix crash of `queue_free()` when main loop is not SceneTree
-rw-r--r-- | scene/main/node.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 377620af64..5dd0911694 100644 --- a/scene/main/node.cpp +++ b/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); } } |