Don't access Node3D/Node2D/Control global transform in `reparent` unless needed

Fixes #89002.

Co-authored-by: Tamás Gálffy <ezittgtx@gmail.com>
This commit is contained in:
Rémi Verschelde 2024-02-29 12:46:07 +01:00
parent b5d30f9efe
commit 810a0dbff1
No known key found for this signature in database
GPG Key ID: C3336907360768E1
3 changed files with 12 additions and 6 deletions

View File

@ -143,10 +143,12 @@ void Node2D::_update_transform() {
void Node2D::reparent(Node *p_parent, bool p_keep_global_transform) {
ERR_THREAD_GUARD;
Transform2D temp = get_global_transform();
Node::reparent(p_parent);
if (p_keep_global_transform) {
Transform2D temp = get_global_transform();
Node::reparent(p_parent);
set_global_transform(temp);
} else {
Node::reparent(p_parent);
}
}

View File

@ -719,10 +719,12 @@ void Node3D::set_disable_gizmos(bool p_enabled) {
void Node3D::reparent(Node *p_parent, bool p_keep_global_transform) {
ERR_THREAD_GUARD;
Transform3D temp = get_global_transform();
Node::reparent(p_parent);
if (p_keep_global_transform) {
Transform3D temp = get_global_transform();
Node::reparent(p_parent);
set_global_transform(temp);
} else {
Node::reparent(p_parent);
}
}

View File

@ -188,10 +188,12 @@ Size2 Control::_edit_get_minimum_size() const {
void Control::reparent(Node *p_parent, bool p_keep_global_transform) {
ERR_MAIN_THREAD_GUARD;
Transform2D temp = get_global_transform();
Node::reparent(p_parent);
if (p_keep_global_transform) {
Transform2D temp = get_global_transform();
Node::reparent(p_parent);
set_global_position(temp.get_origin());
} else {
Node::reparent(p_parent);
}
}