Skip to content

Commit 0b1266b

Browse files
committed
Fix physics platform crash
Physics body previously stored the RID of a collision object and accessed it on the next frame, leading to a crash if the object had been deleted. This PR checks the object still exists via the ObjectID prior to access.
1 parent f77bc87 commit 0b1266b

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)