From 47657cd140c7df4aa7266fa3b98a701c5660c005 Mon Sep 17 00:00:00 2001 From: Marcel Admiraal Date: Wed, 13 Jan 2021 13:30:42 +0000 Subject: [PATCH] Only remove Bullet's body constraints when removing body from space --- modules/bullet/rigid_body_bullet.cpp | 3 ++- modules/bullet/space_bullet.cpp | 6 +++++- modules/bullet/space_bullet.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index e37a12e6ee27..65bf7275ba40 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -338,7 +338,8 @@ void RigidBodyBullet::set_space(SpaceBullet *p_space) { if (space) { can_integrate_forces = false; isScratchedSpaceOverrideModificator = false; - + // Remove any constraints + space->remove_rigid_body_constraints(this); // Remove this object form the physics world space->remove_rigid_body(this); } diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index 9513c2103783..f89264f50553 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -497,7 +497,7 @@ void SpaceBullet::add_rigid_body(RigidBodyBullet *p_body) { } } -void SpaceBullet::remove_rigid_body(RigidBodyBullet *p_body) { +void SpaceBullet::remove_rigid_body_constraints(RigidBodyBullet *p_body) { btRigidBody *btBody = p_body->get_bt_rigid_body(); int constraints = btBody->getNumConstraintRefs(); @@ -507,6 +507,10 @@ void SpaceBullet::remove_rigid_body(RigidBodyBullet *p_body) { dynamicsWorld->removeConstraint(btBody->getConstraintRef(i)); } } +} + +void SpaceBullet::remove_rigid_body(RigidBodyBullet *p_body) { + btRigidBody *btBody = p_body->get_bt_rigid_body(); if (p_body->is_static()) { dynamicsWorld->removeCollisionObject(btBody); diff --git a/modules/bullet/space_bullet.h b/modules/bullet/space_bullet.h index 4b01ed9220fd..a1c800858b1e 100644 --- a/modules/bullet/space_bullet.h +++ b/modules/bullet/space_bullet.h @@ -149,6 +149,7 @@ class SpaceBullet : public RIDBullet { void reload_collision_filters(AreaBullet *p_area); void add_rigid_body(RigidBodyBullet *p_body); + void remove_rigid_body_constraints(RigidBodyBullet *p_body); void remove_rigid_body(RigidBodyBullet *p_body); void reload_collision_filters(RigidBodyBullet *p_body);