Fix crash of queue_free() when main loop is not SceneTree

(cherry picked from commit 3b08d0e852)
This commit is contained in:
Haoyu Qiu 2022-10-25 09:31:56 +08:00 committed by Rémi Verschelde
parent 6d030f93b7
commit 3b869e8027
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 5 additions and 1 deletions

View File

@ -2887,10 +2887,14 @@ void Node::print_stray_nodes() {
}
void Node::queue_delete() {
// 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);
}
}