diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-01-13 17:15:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-13 17:15:45 +0100 |
commit | 8d4698db3656457eccfc54ea84716af146fb49a9 (patch) | |
tree | ec75fc2d82586d73a138989d7f83301ddb7963ea | |
parent | 0b409d89d04d4cfed9fb559df8a3b379aba6ea2b (diff) | |
parent | 797a7fc6cc9c9583546447771fbf2b9c3b8cb576 (diff) |
Merge pull request #45159 from madmiraal/fix-45145
Only remove Bullet's body constraints when removing body from space
-rw-r--r-- | modules/bullet/rigid_body_bullet.cpp | 3 | ||||
-rw-r--r-- | modules/bullet/space_bullet.cpp | 6 | ||||
-rw-r--r-- | 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 7a53f91b33..4763098584 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -322,7 +322,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 a8d55b59b3..5cbaeb32d7 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -477,7 +477,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(); @@ -487,6 +487,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 42f982d5f0..0f2482e551 100644 --- a/modules/bullet/space_bullet.h +++ b/modules/bullet/space_bullet.h @@ -151,6 +151,7 @@ public: 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); |