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

Clear only owners that are no longer in the same tree #56519

Merged
merged 1 commit into from
Jan 5, 2022
Merged
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
21 changes: 19 additions & 2 deletions scene/main/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,32 @@ void Node::_propagate_enter_tree() {
}

void Node::_propagate_after_exit_tree() {
// Clear owner if it was not part of the pruned branch
if (data.owner) {
data.owner->data.owned.erase(data.OW);
data.owner = nullptr;
bool found = false;
Node *parent = data.parent;

while (parent) {
if (parent == data.owner) {
found = true;
break;
}

parent = parent->data.parent;
}

if (!found) {
data.owner->data.owned.erase(data.OW);
data.owner = nullptr;
}
}

data.blocked++;
for (int i = data.children.size() - 1; i >= 0; i--) {
data.children[i]->_propagate_after_exit_tree();
}
data.blocked--;

emit_signal(SceneStringNames::get_singleton()->tree_exited);
}

Expand Down