Fix errors in CharacterBody 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.
This commit is contained in:
@@ -837,8 +837,17 @@ void BulletPhysicsServer3D::body_set_ray_pickable(RID p_body, bool p_enable) {
|
||||
}
|
||||
|
||||
PhysicsDirectBodyState3D *BulletPhysicsServer3D::body_get_direct_state(RID p_body) {
|
||||
if (!rigid_body_owner.owns(p_body)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body);
|
||||
ERR_FAIL_COND_V(!body, nullptr);
|
||||
|
||||
if (!body->get_space()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return BulletPhysicsDirectBodyState3D::get_singleton(body);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user