From aa42e8920b840a82f0d0d0e1975cdfa66b0b4bd1 Mon Sep 17 00:00:00 2001 From: Eryk Dwornicki Date: Sat, 27 Feb 2021 17:55:19 +0100 Subject: Move removal of the constraints from bodies to Joint3DSW destructor Joint3DSW instances are also destroyed without explicitly calling free() for example when changing constrainted bodies at runtime using set_node method. --- servers/physics_3d/joints_3d_sw.h | 9 +++++++++ servers/physics_3d/physics_server_3d_sw.cpp | 3 --- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'servers') diff --git a/servers/physics_3d/joints_3d_sw.h b/servers/physics_3d/joints_3d_sw.h index 1fe573c69e..225a71aca9 100644 --- a/servers/physics_3d/joints_3d_sw.h +++ b/servers/physics_3d/joints_3d_sw.h @@ -49,6 +49,15 @@ public: _FORCE_INLINE_ Joint3DSW(Body3DSW **p_body_ptr = nullptr, int p_body_count = 0) : Constraint3DSW(p_body_ptr, p_body_count) { } + + virtual ~Joint3DSW() { + for (int i = 0; i < get_body_count(); i++) { + Body3DSW *body = get_body_ptr()[i]; + if (body) { + body->remove_constraint(this); + } + } + } }; #endif // JOINTS_SW_H diff --git a/servers/physics_3d/physics_server_3d_sw.cpp b/servers/physics_3d/physics_server_3d_sw.cpp index 735e9094d2..6bbef09907 100644 --- a/servers/physics_3d/physics_server_3d_sw.cpp +++ b/servers/physics_3d/physics_server_3d_sw.cpp @@ -1312,9 +1312,6 @@ void PhysicsServer3DSW::free(RID p_rid) { } else if (joint_owner.owns(p_rid)) { Joint3DSW *joint = joint_owner.getornull(p_rid); - for (int i = 0; i < joint->get_body_count(); i++) { - joint->get_body_ptr()[i]->remove_constraint(joint); - } joint_owner.free(p_rid); memdelete(joint); -- cgit v1.2.3