You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Merge pull request #74054 from Rindbee/clean_up_owner
Avoid crash when adjusting a node tree that is not in the tree
This commit is contained in:
@@ -202,6 +202,10 @@ void Node::_notification(int p_notification) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.owner) {
|
||||||
|
_clean_up_owner();
|
||||||
|
}
|
||||||
|
|
||||||
if (data.parent) {
|
if (data.parent) {
|
||||||
data.parent->remove_child(this);
|
data.parent->remove_child(this);
|
||||||
}
|
}
|
||||||
@@ -301,11 +305,7 @@ void Node::_propagate_after_exit_tree() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
if (data.unique_name_in_owner) {
|
_clean_up_owner();
|
||||||
_release_unique_name_in_owner();
|
|
||||||
}
|
|
||||||
data.owner->data.owned.erase(data.OW);
|
|
||||||
data.owner = nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1876,12 +1876,7 @@ bool Node::is_unique_name_in_owner() const {
|
|||||||
void Node::set_owner(Node *p_owner) {
|
void Node::set_owner(Node *p_owner) {
|
||||||
ERR_MAIN_THREAD_GUARD
|
ERR_MAIN_THREAD_GUARD
|
||||||
if (data.owner) {
|
if (data.owner) {
|
||||||
if (data.unique_name_in_owner) {
|
_clean_up_owner();
|
||||||
_release_unique_name_in_owner();
|
|
||||||
}
|
|
||||||
data.owner->data.owned.erase(data.OW);
|
|
||||||
data.OW = nullptr;
|
|
||||||
data.owner = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ERR_FAIL_COND(p_owner == this);
|
ERR_FAIL_COND(p_owner == this);
|
||||||
@@ -1915,6 +1910,17 @@ Node *Node::get_owner() const {
|
|||||||
return data.owner;
|
return data.owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Node::_clean_up_owner() {
|
||||||
|
ERR_FAIL_NULL(data.owner); // Sanity check.
|
||||||
|
|
||||||
|
if (data.unique_name_in_owner) {
|
||||||
|
_release_unique_name_in_owner();
|
||||||
|
}
|
||||||
|
data.owner->data.owned.erase(data.OW);
|
||||||
|
data.owner = nullptr;
|
||||||
|
data.OW = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
Node *Node::find_common_parent_with(const Node *p_node) const {
|
Node *Node::find_common_parent_with(const Node *p_node) const {
|
||||||
if (this == p_node) {
|
if (this == p_node) {
|
||||||
return const_cast<Node *>(p_node);
|
return const_cast<Node *>(p_node);
|
||||||
@@ -2747,6 +2753,8 @@ void Node::replace_by(Node *p_node, bool p_keep_groups) {
|
|||||||
for (int i = 0; i < get_child_count(); i++) {
|
for (int i = 0; i < get_child_count(); i++) {
|
||||||
find_owned_by(data.owner, get_child(i), &owned_by_owner);
|
find_owned_by(data.owner, get_child(i), &owned_by_owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_clean_up_owner();
|
||||||
}
|
}
|
||||||
|
|
||||||
Node *parent = data.parent;
|
Node *parent = data.parent;
|
||||||
|
|||||||
@@ -236,6 +236,8 @@ private:
|
|||||||
void _release_unique_name_in_owner();
|
void _release_unique_name_in_owner();
|
||||||
void _acquire_unique_name_in_owner();
|
void _acquire_unique_name_in_owner();
|
||||||
|
|
||||||
|
void _clean_up_owner();
|
||||||
|
|
||||||
_FORCE_INLINE_ void _update_children_cache() const {
|
_FORCE_INLINE_ void _update_children_cache() const {
|
||||||
if (unlikely(data.children_cache_dirty)) {
|
if (unlikely(data.children_cache_dirty)) {
|
||||||
_update_children_cache_impl();
|
_update_children_cache_impl();
|
||||||
|
|||||||
Reference in New Issue
Block a user