Checking validity of world reference before using it. Fix #54094.

This commit is contained in:
Bastien JAUNY 2021-10-23 15:01:15 +02:00
parent 5e92619a64
commit a6ca61797c
2 changed files with 6 additions and 3 deletions

View file

@ -44,7 +44,9 @@ void CollisionObject2D::_notification(int p_what) {
Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform); Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform);
} }
RID space = get_world_2d()->get_space(); Ref<World2D> world_ref = get_world_2d();
ERR_FAIL_COND(!world_ref.is_valid());
RID space = world_ref->get_space();
if (area) { if (area) {
Physics2DServer::get_singleton()->area_set_space(rid, space); Physics2DServer::get_singleton()->area_set_space(rid, space);
} else { } else {

View file

@ -60,13 +60,14 @@ void CollisionObject::_notification(int p_what) {
PhysicsServer::get_singleton()->body_set_state(rid, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform()); PhysicsServer::get_singleton()->body_set_state(rid, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform());
} }
RID space = get_world()->get_space(); Ref<World> world_ref = get_world();
ERR_FAIL_COND(!world_ref.is_valid());
RID space = world_ref->get_space();
if (area) { if (area) {
PhysicsServer::get_singleton()->area_set_space(rid, space); PhysicsServer::get_singleton()->area_set_space(rid, space);
} else { } else {
PhysicsServer::get_singleton()->body_set_space(rid, space); PhysicsServer::get_singleton()->body_set_space(rid, space);
} }
_update_pickable(); _update_pickable();
//get space //get space
} break; } break;