1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-11 13:10:58 +00:00

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.
This commit is contained in:
PouleyKetchoupp
2021-11-09 15:15:40 -07:00
parent 403ca51dd2
commit b93aeec4a2
7 changed files with 33 additions and 3 deletions

View File

@@ -881,8 +881,17 @@ int PhysicsServerSW::body_test_ray_separation(RID p_body, const Transform &p_tra
}
PhysicsDirectBodyState *PhysicsServerSW::body_get_direct_state(RID p_body) {
if (!body_owner.owns(p_body)) {
return nullptr;
}
BodySW *body = body_owner.get(p_body);
ERR_FAIL_COND_V(!body, nullptr);
if (!body->get_space()) {
return nullptr;
}
ERR_FAIL_COND_V_MSG(body->get_space()->is_locked(), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification.");
direct_state->body = body;