From a6ca61797cd4ccb169ada31a75017aea7bd7b822 Mon Sep 17 00:00:00 2001 From: Bastien JAUNY Date: Sat, 23 Oct 2021 15:01:15 +0200 Subject: [PATCH] Checking validity of world reference before using it. Fix #54094. --- scene/2d/collision_object_2d.cpp | 4 +++- scene/3d/collision_object.cpp | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index fa926404bcd..11302073fcf 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -44,7 +44,9 @@ void CollisionObject2D::_notification(int p_what) { Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform); } - RID space = get_world_2d()->get_space(); + Ref world_ref = get_world_2d(); + ERR_FAIL_COND(!world_ref.is_valid()); + RID space = world_ref->get_space(); if (area) { Physics2DServer::get_singleton()->area_set_space(rid, space); } else { diff --git a/scene/3d/collision_object.cpp b/scene/3d/collision_object.cpp index 78b3f1b072f..2c738260482 100644 --- a/scene/3d/collision_object.cpp +++ b/scene/3d/collision_object.cpp @@ -60,13 +60,14 @@ void CollisionObject::_notification(int p_what) { PhysicsServer::get_singleton()->body_set_state(rid, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform()); } - RID space = get_world()->get_space(); + Ref world_ref = get_world(); + ERR_FAIL_COND(!world_ref.is_valid()); + RID space = world_ref->get_space(); if (area) { PhysicsServer::get_singleton()->area_set_space(rid, space); } else { PhysicsServer::get_singleton()->body_set_space(rid, space); } - _update_pickable(); //get space } break;