Skip to content

Commit 7900597

Browse files
committed
Merge pull request godotengine#88947 from lawnjelly/fix_physics_platform_rid
Fix physics platform crash
2 parents bd76372 + 0b1266b commit 7900597

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

scene/3d/physics/character_body_3d.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,15 @@ bool CharacterBody3D::move_and_slide() {
5656
excluded = (platform_wall_layers & platform_layer) == 0;
5757
}
5858
if (!excluded) {
59-
//this approach makes sure there is less delay between the actual body velocity and the one we saved
60-
PhysicsDirectBodyState3D *bs = PhysicsServer3D::get_singleton()->body_get_direct_state(platform_rid);
59+
PhysicsDirectBodyState3D *bs = nullptr;
60+
61+
// We need to check the platform_rid object still exists before accessing.
62+
// A valid RID is no guarantee that the object has not been deleted.
63+
if (ObjectDB::get_instance(platform_object_id)) {
64+
//this approach makes sure there is less delay between the actual body velocity and the one we saved
65+
bs = PhysicsServer3D::get_singleton()->body_get_direct_state(platform_rid);
66+
}
67+
6168
if (bs) {
6269
Vector3 local_position = gt.origin - bs->get_transform().origin;
6370
current_platform_velocity = bs->get_velocity_at_local_position(local_position);

0 commit comments

Comments
 (0)