diff options
author | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2021-11-09 15:30:15 -0700 |
---|---|---|
committer | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2021-11-10 08:27:33 -0700 |
commit | bfd0d33244f565ffca17b0578edc3a82b76a7204 (patch) | |
tree | 79892900a07fb3538d64587e052045d10ecd1c3f /scene/3d/physics_body_3d.cpp | |
parent | e8870ddefc36f6e04dc6212ab5ca1d6391739539 (diff) | |
download | redot-engine-bfd0d33244f565ffca17b0578edc3a82b76a7204.tar.gz |
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.
Diffstat (limited to 'scene/3d/physics_body_3d.cpp')
-rw-r--r-- | scene/3d/physics_body_3d.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index d0506227b4..ea881b6d54 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -1145,6 +1145,10 @@ bool CharacterBody3D::move_and_slide() { if (bs) { Vector3 local_position = gt.origin - bs->get_transform().origin; current_platform_velocity = bs->get_velocity_at_local_position(local_position); + } else { + // Body is removed or destroyed, invalidate floor. + current_platform_velocity = Vector3(); + platform_rid = RID(); } } else { current_platform_velocity = Vector3(); |