From 810a0dbff12585cebf37681e5e4007550b259c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 29 Feb 2024 12:46:07 +0100 Subject: [PATCH] Don't access Node3D/Node2D/Control global transform in `reparent` unless needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #89002. Co-authored-by: Tamás Gálffy --- scene/2d/node_2d.cpp | 6 ++++-- scene/3d/node_3d.cpp | 6 ++++-- scene/gui/control.cpp | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 0a5f696992d..aae7eff7bd0 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -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); } } diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp index ab058b5646b..5c081a0b47d 100644 --- a/scene/3d/node_3d.cpp +++ b/scene/3d/node_3d.cpp @@ -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); } } diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 235895ce473..e9f1606d668 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -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); } }