Fix errors in KinematicBody when floor is destroyed or removed

In all physics servers, body_get_direct_state() now silently returns
nullptr when the body has been already freed or is removed from space,
so the client code can detect this state and invalidate the body rid.

In 2D, there is no change in behavior (just no more errors).

In 3D, the Bullet server returned a valid direct body state when the
body was removed from the physics space, but in this case it didn't
make sense to use the information from the body state.

(cherry picked from commit b93aeec4a2)
This commit is contained in:
PouleyKetchoupp
2021-11-09 15:15:40 -07:00
committed by Rémi Verschelde
parent 619c1e506e
commit 7344beafdd
7 changed files with 33 additions and 3 deletions

View File

@@ -851,8 +851,17 @@ bool BulletPhysicsServer::body_is_ray_pickable(RID p_body) const {
}
PhysicsDirectBodyState *BulletPhysicsServer::body_get_direct_state(RID p_body) {
if (!rigid_body_owner.owns(p_body)) {
return nullptr;
}
RigidBodyBullet *body = rigid_body_owner.get(p_body);
ERR_FAIL_COND_V(!body, nullptr);
if (!body->get_space()) {
return nullptr;
}
return BulletPhysicsDirectBodyState::get_singleton(body);
}