Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that SceneTree is initialized and finalized at correct time #72248

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions scene/main/scene_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,8 @@ void SceneTree::set_group(const StringName &p_group, const String &p_name, const

void SceneTree::initialize() {
ERR_FAIL_NULL(root);
initialized = true;
root->_set_tree(this);
MainLoop::initialize();
root->_set_tree(this);
}

bool SceneTree::physics_process(double p_time) {
Expand Down Expand Up @@ -618,20 +617,18 @@ void SceneTree::finalize() {

_flush_ugc();

initialized = false;

MainLoop::finalize();

if (root) {
root->_set_tree(nullptr);
root->_propagate_after_exit_tree();
memdelete(root); //delete root
root = nullptr;

// In case deletion of some objects was queued when destructing the `root`.
// E.g. if `queue_free()` was called for some node outside the tree when handling NOTIFICATION_PREDELETE for some node in the tree.
_flush_delete_queue();
}

// In case deletion of some objects was queued when destructing the `root`.
// E.g. if `queue_free()` was called for some node outside the tree when handling NOTIFICATION_PREDELETE for some node in the tree.
_flush_delete_queue();
MainLoop::finalize();

// Cleanup timers.
for (Ref<SceneTreeTimer> &timer : timers) {
Expand Down
1 change: 0 additions & 1 deletion scene/main/scene_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class SceneTree : public MainLoop {

HashMap<StringName, Group> group_map;
bool _quit = false;
bool initialized = false;

StringName tree_changed_name = "tree_changed";
StringName node_added_name = "node_added";
Expand Down