Cache world in VisibilityNotifier3D to avoid crash

This commit is contained in:
kobewi 2021-01-27 20:38:40 +01:00
parent 69f77e83bf
commit 4d172f1fca
2 changed files with 8 additions and 3 deletions

View file

@ -80,13 +80,16 @@ AABB VisibilityNotifier3D::get_aabb() const {
void VisibilityNotifier3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
get_world_3d()->_register_notifier(this, get_global_transform().xform(aabb));
world = get_world_3d();
ERR_FAIL_COND(!world.is_valid());
world->_register_notifier(this, get_global_transform().xform(aabb));
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
get_world_3d()->_update_notifier(this, get_global_transform().xform(aabb));
world->_update_notifier(this, get_global_transform().xform(aabb));
} break;
case NOTIFICATION_EXIT_WORLD: {
get_world_3d()->_remove_notifier(this);
ERR_FAIL_COND(!world.is_valid());
world->_remove_notifier(this);
} break;
}
}

View file

@ -33,10 +33,12 @@
#include "scene/3d/node_3d.h"
class World3D;
class Camera3D;
class VisibilityNotifier3D : public Node3D {
GDCLASS(VisibilityNotifier3D, Node3D);
Ref<World3D> world;
Set<Camera3D *> cameras;
AABB aabb;