Cache world in VisibilityNotifier3D to avoid crash

(cherry picked from commit 4d172f1fca)
This commit is contained in:
kobewi 2021-01-27 20:38:40 +01:00 committed by Rémi Verschelde
parent 8c22d5a973
commit 7a6ab8c558
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 8 additions and 3 deletions

View file

@ -85,15 +85,18 @@ void VisibilityNotifier::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_ENTER_WORLD: { 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; } break;
case NOTIFICATION_TRANSFORM_CHANGED: { case NOTIFICATION_TRANSFORM_CHANGED: {
get_world()->_update_notifier(this, get_global_transform().xform(aabb)); world->_update_notifier(this, get_global_transform().xform(aabb));
} break; } break;
case NOTIFICATION_EXIT_WORLD: { case NOTIFICATION_EXIT_WORLD: {
get_world()->_remove_notifier(this); ERR_FAIL_COND(!world.is_valid());
world->_remove_notifier(this);
} break; } break;
} }
} }

View file

@ -33,11 +33,13 @@
#include "scene/3d/spatial.h" #include "scene/3d/spatial.h"
class World;
class Camera; class Camera;
class VisibilityNotifier : public Spatial { class VisibilityNotifier : public Spatial {
GDCLASS(VisibilityNotifier, Spatial); GDCLASS(VisibilityNotifier, Spatial);
Ref<World> world;
Set<Camera *> cameras; Set<Camera *> cameras;
AABB aabb; AABB aabb;