Remove any constraints connected to a Bullet body when removing it
This commit is contained in:
parent
803f6d2388
commit
4bfcaeff5a
3 changed files with 12 additions and 18 deletions
|
@ -339,9 +339,6 @@ void RigidBodyBullet::set_space(SpaceBullet *p_space) {
|
||||||
can_integrate_forces = false;
|
can_integrate_forces = false;
|
||||||
isScratchedSpaceOverrideModificator = false;
|
isScratchedSpaceOverrideModificator = false;
|
||||||
|
|
||||||
// Remove all eventual constraints
|
|
||||||
assert_no_constraints();
|
|
||||||
|
|
||||||
// Remove this object form the physics world
|
// Remove this object form the physics world
|
||||||
space->remove_rigid_body(this);
|
space->remove_rigid_body(this);
|
||||||
}
|
}
|
||||||
|
@ -461,17 +458,6 @@ bool RigidBodyBullet::was_colliding(RigidBodyBullet *p_other_object) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBodyBullet::assert_no_constraints() {
|
|
||||||
if (btBody->getNumConstraintRefs()) {
|
|
||||||
WARN_PRINT("A body with a joints is destroyed. Please check the implementation in order to destroy the joint before the body.");
|
|
||||||
}
|
|
||||||
/*for(int i = btBody->getNumConstraintRefs()-1; 0<=i; --i){
|
|
||||||
btTypedConstraint* btConst = btBody->getConstraintRef(i);
|
|
||||||
JointBullet* joint = static_cast<JointBullet*>( btConst->getUserConstraintPtr() );
|
|
||||||
space->removeConstraint(joint);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void RigidBodyBullet::set_activation_state(bool p_active) {
|
void RigidBodyBullet::set_activation_state(bool p_active) {
|
||||||
if (p_active) {
|
if (p_active) {
|
||||||
btBody->activate();
|
btBody->activate();
|
||||||
|
|
|
@ -270,8 +270,6 @@ public:
|
||||||
bool add_collision_object(RigidBodyBullet *p_otherObject, const Vector3 &p_hitWorldLocation, const Vector3 &p_hitLocalLocation, const Vector3 &p_hitNormal, const float &p_appliedImpulse, int p_other_shape_index, int p_local_shape_index);
|
bool add_collision_object(RigidBodyBullet *p_otherObject, const Vector3 &p_hitWorldLocation, const Vector3 &p_hitLocalLocation, const Vector3 &p_hitNormal, const float &p_appliedImpulse, int p_other_shape_index, int p_local_shape_index);
|
||||||
bool was_colliding(RigidBodyBullet *p_other_object);
|
bool was_colliding(RigidBodyBullet *p_other_object);
|
||||||
|
|
||||||
void assert_no_constraints();
|
|
||||||
|
|
||||||
void set_activation_state(bool p_active);
|
void set_activation_state(bool p_active);
|
||||||
bool is_active() const;
|
bool is_active() const;
|
||||||
|
|
||||||
|
|
|
@ -498,10 +498,20 @@ void SpaceBullet::add_rigid_body(RigidBodyBullet *p_body) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpaceBullet::remove_rigid_body(RigidBodyBullet *p_body) {
|
void SpaceBullet::remove_rigid_body(RigidBodyBullet *p_body) {
|
||||||
|
btRigidBody *btBody = p_body->get_bt_rigid_body();
|
||||||
|
|
||||||
|
int constraints = btBody->getNumConstraintRefs();
|
||||||
|
if (constraints > 0) {
|
||||||
|
WARN_PRINT("A body connected to joints was removed. Ensure bodies are disconnected from joints before removing them.");
|
||||||
|
for (int i = 0; i < constraints; i++) {
|
||||||
|
dynamicsWorld->removeConstraint(btBody->getConstraintRef(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (p_body->is_static()) {
|
if (p_body->is_static()) {
|
||||||
dynamicsWorld->removeCollisionObject(p_body->get_bt_rigid_body());
|
dynamicsWorld->removeCollisionObject(btBody);
|
||||||
} else {
|
} else {
|
||||||
dynamicsWorld->removeRigidBody(p_body->get_bt_rigid_body());
|
dynamicsWorld->removeRigidBody(btBody);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue