From 7a6ab8c558195cc05c90d80363efa78d8a76a071 Mon Sep 17 00:00:00 2001 From: kobewi Date: Wed, 27 Jan 2021 20:38:40 +0100 Subject: [PATCH] Cache world in VisibilityNotifier3D to avoid crash (cherry picked from commit 4d172f1fcab6463f0afce3ed4715f67282523a49) --- scene/3d/visibility_notifier.cpp | 9 ++++++--- scene/3d/visibility_notifier.h | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/scene/3d/visibility_notifier.cpp b/scene/3d/visibility_notifier.cpp index b33746451ab..5231b2ea1ea 100644 --- a/scene/3d/visibility_notifier.cpp +++ b/scene/3d/visibility_notifier.cpp @@ -85,15 +85,18 @@ void VisibilityNotifier::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_WORLD: { - get_world()->_register_notifier(this, get_global_transform().xform(aabb)); + world = get_world(); + ERR_FAIL_COND(!world.is_valid()); + world->_register_notifier(this, get_global_transform().xform(aabb)); } break; case NOTIFICATION_TRANSFORM_CHANGED: { - get_world()->_update_notifier(this, get_global_transform().xform(aabb)); + world->_update_notifier(this, get_global_transform().xform(aabb)); } break; case NOTIFICATION_EXIT_WORLD: { - get_world()->_remove_notifier(this); + ERR_FAIL_COND(!world.is_valid()); + world->_remove_notifier(this); } break; } } diff --git a/scene/3d/visibility_notifier.h b/scene/3d/visibility_notifier.h index 47418bbbb48..170498e4094 100644 --- a/scene/3d/visibility_notifier.h +++ b/scene/3d/visibility_notifier.h @@ -33,11 +33,13 @@ #include "scene/3d/spatial.h" +class World; class Camera; class VisibilityNotifier : public Spatial { GDCLASS(VisibilityNotifier, Spatial); + Ref world; Set cameras; AABB aabb;