Skip to content

Commit

Permalink
Merge pull request #45159 from madmiraal/fix-45145
Browse files Browse the repository at this point in the history
Only remove Bullet's body constraints when removing body from space
  • Loading branch information
akien-mga authored Jan 13, 2021
2 parents 0b409d8 + 797a7fc commit 8d4698d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion modules/bullet/rigid_body_bullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 5 additions & 1 deletion modules/bullet/space_bullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions modules/bullet/space_bullet.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,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);

Expand Down

0 comments on commit 8d4698d

Please sign in to comment.