diff options
author | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-02-05 16:40:49 +0100 |
---|---|---|
committer | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-02-05 16:40:49 +0100 |
commit | fb1662b939391cd2af9ce1cc6dba87b364f0ee77 (patch) | |
tree | 20cb988fa8fe0f26d3d4b8ee1d98393f19ec2de2 | |
parent | 63d6bda8e95ac992da74e84b2f3be62f3d85190b (diff) | |
download | redot-engine-fb1662b939391cd2af9ce1cc6dba87b364f0ee77.tar.gz |
Fix crash with `PhysicsBody2D/3D::get_gravity` with invalid state
-rw-r--r-- | scene/2d/physics_body_2d.cpp | 4 | ||||
-rw-r--r-- | scene/3d/physics_body_3d.cpp | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 7a131916e8..af9008f452 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -147,7 +147,9 @@ bool PhysicsBody2D::test_move(const Transform2D &p_from, const Vector2 &p_motion } Vector2 PhysicsBody2D::get_gravity() const { - return PhysicsServer2D::get_singleton()->body_get_direct_state(get_rid())->get_total_gravity(); + PhysicsDirectBodyState2D *state = PhysicsServer2D::get_singleton()->body_get_direct_state(get_rid()); + ERR_FAIL_NULL_V(state, Vector2()); + return state->get_total_gravity(); } TypedArray<PhysicsBody2D> PhysicsBody2D::get_collision_exceptions() { diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index 1f78928b94..7d08d767c7 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -189,7 +189,9 @@ bool PhysicsBody3D::test_move(const Transform3D &p_from, const Vector3 &p_motion } Vector3 PhysicsBody3D::get_gravity() const { - return PhysicsServer3D::get_singleton()->body_get_direct_state(get_rid())->get_total_gravity(); + PhysicsDirectBodyState3D *state = PhysicsServer3D::get_singleton()->body_get_direct_state(get_rid()); + ERR_FAIL_NULL_V(state, Vector3()); + return state->get_total_gravity(); } void PhysicsBody3D::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock) { |