Merge pull request #55512 from RandomShaper/better_node_delete
This commit is contained in:
commit
91b5c358fc
|
@ -152,12 +152,6 @@ void Node::_notification(int p_notification) {
|
||||||
data.in_constructor = false;
|
data.in_constructor = false;
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_PREDELETE: {
|
case NOTIFICATION_PREDELETE: {
|
||||||
set_owner(nullptr);
|
|
||||||
|
|
||||||
while (data.owned.size()) {
|
|
||||||
data.owned.front()->get()->set_owner(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.parent) {
|
if (data.parent) {
|
||||||
data.parent->remove_child(this);
|
data.parent->remove_child(this);
|
||||||
}
|
}
|
||||||
|
@ -165,10 +159,8 @@ void Node::_notification(int p_notification) {
|
||||||
// kill children as cleanly as possible
|
// kill children as cleanly as possible
|
||||||
while (data.children.size()) {
|
while (data.children.size()) {
|
||||||
Node *child = data.children[data.children.size() - 1]; //begin from the end because its faster and more consistent with creation
|
Node *child = data.children[data.children.size() - 1]; //begin from the end because its faster and more consistent with creation
|
||||||
remove_child(child);
|
|
||||||
memdelete(child);
|
memdelete(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,8 +229,12 @@ void Node::_propagate_enter_tree() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::_propagate_after_exit_tree() {
|
void Node::_propagate_after_exit_tree() {
|
||||||
|
if (data.owner) {
|
||||||
|
data.owner->data.owned.erase(data.OW);
|
||||||
|
data.owner = nullptr;
|
||||||
|
}
|
||||||
data.blocked++;
|
data.blocked++;
|
||||||
for (int i = 0; i < data.children.size(); i++) {
|
for (int i = data.children.size() - 1; i >= 0; i--) {
|
||||||
data.children[i]->_propagate_after_exit_tree();
|
data.children[i]->_propagate_after_exit_tree();
|
||||||
}
|
}
|
||||||
data.blocked--;
|
data.blocked--;
|
||||||
|
@ -1144,31 +1140,6 @@ void Node::add_sibling(Node *p_sibling, bool p_legible_unique_name) {
|
||||||
data.parent->_move_child(p_sibling, get_index() + 1);
|
data.parent->_move_child(p_sibling, get_index() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::_propagate_validate_owner() {
|
|
||||||
if (data.owner) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < data.children.size(); i++) {
|
|
||||||
data.children[i]->_propagate_validate_owner();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Node::remove_child(Node *p_child) {
|
void Node::remove_child(Node *p_child) {
|
||||||
ERR_FAIL_NULL(p_child);
|
ERR_FAIL_NULL(p_child);
|
||||||
ERR_FAIL_COND_MSG(data.blocked > 0, "Parent node is busy setting up children, remove_node() failed. Consider using call_deferred(\"remove_child\", child) instead.");
|
ERR_FAIL_COND_MSG(data.blocked > 0, "Parent node is busy setting up children, remove_node() failed. Consider using call_deferred(\"remove_child\", child) instead.");
|
||||||
|
@ -1222,9 +1193,6 @@ void Node::remove_child(Node *p_child) {
|
||||||
p_child->data.parent = nullptr;
|
p_child->data.parent = nullptr;
|
||||||
p_child->data.pos = -1;
|
p_child->data.pos = -1;
|
||||||
|
|
||||||
// validate owner
|
|
||||||
p_child->_propagate_validate_owner();
|
|
||||||
|
|
||||||
if (data.inside_tree) {
|
if (data.inside_tree) {
|
||||||
p_child->_propagate_after_exit_tree();
|
p_child->_propagate_after_exit_tree();
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,6 @@ private:
|
||||||
void _propagate_ready();
|
void _propagate_ready();
|
||||||
void _propagate_exit_tree();
|
void _propagate_exit_tree();
|
||||||
void _propagate_after_exit_tree();
|
void _propagate_after_exit_tree();
|
||||||
void _propagate_validate_owner();
|
|
||||||
void _print_stray_nodes();
|
void _print_stray_nodes();
|
||||||
void _propagate_process_owner(Node *p_owner, int p_pause_notification, int p_enabled_notification);
|
void _propagate_process_owner(Node *p_owner, int p_pause_notification, int p_enabled_notification);
|
||||||
Array _get_node_and_resource(const NodePath &p_path);
|
Array _get_node_and_resource(const NodePath &p_path);
|
||||||
|
|
Loading…
Reference in New Issue