Browse Source

Cache world in VisibilityNotifier3D to avoid crash

(cherry picked from commit 4d172f1fcab6463f0afce3ed4715f67282523a49)
kobewi 4 years ago
parent
commit
7a6ab8c558
2 changed files with 8 additions and 3 deletions
  1. 6 3
      scene/3d/visibility_notifier.cpp
  2. 2 0
      scene/3d/visibility_notifier.h

+ 6 - 3
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;
 	}
 }

+ 2 - 0
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> world;
 	Set<Camera *> cameras;
 
 	AABB aabb;