summaryrefslogtreecommitdiff
path: root/scene/3d
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-05-30 18:31:15 +0200
committerGitHub <noreply@github.com>2019-05-30 18:31:15 +0200
commit62b868fd37bce1d38fdb1a158a6064cd19eed411 (patch)
treef9833bb02c7d7bae70673be44bf1c555460fa525 /scene/3d
parent6895ad303b51aaf84a568c982e3622049a50ed37 (diff)
parente3fc5fb1dba48b300d31eb519a7ff4d8f535a9d0 (diff)
Merge pull request #26942 from RandomShaper/fix-vp-issues
Fix Viewport and Camera issues
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/camera.cpp28
-rw-r--r--scene/3d/camera.h1
2 files changed, 19 insertions, 10 deletions
diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp
index 29002c6701..a00f2173c0 100644
--- a/scene/3d/camera.cpp
+++ b/scene/3d/camera.cpp
@@ -106,9 +106,15 @@ void Camera::_notification(int p_what) {
case NOTIFICATION_ENTER_WORLD: {
- bool first_camera = get_viewport()->_camera_add(this);
- if (!get_tree()->is_node_being_edited(this) && (current || first_camera))
- make_current();
+ // Needs to track the Viewport because it's needed on NOTIFICATION_EXIT_WORLD
+ // and Spatial will handle it first, including clearing its reference to the Viewport,
+ // therefore making it impossible to subclasses to access it
+ viewport = get_viewport();
+ ERR_FAIL_COND(!viewport);
+
+ bool first_camera = viewport->_camera_add(this);
+ if (current || first_camera)
+ viewport->_camera_set(this);
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
@@ -130,17 +136,20 @@ void Camera::_notification(int p_what) {
}
}
- get_viewport()->_camera_remove(this);
+ if (viewport) {
+ viewport->_camera_remove(this);
+ viewport = NULL;
+ }
} break;
case NOTIFICATION_BECAME_CURRENT: {
- if (get_world().is_valid()) {
- get_world()->_register_camera(this);
+ if (viewport) {
+ viewport->find_world()->_register_camera(this);
}
} break;
case NOTIFICATION_LOST_CURRENT: {
- if (get_world().is_valid()) {
- get_world()->_remove_camera(this);
+ if (viewport) {
+ viewport->find_world()->_remove_camera(this);
}
} break;
}
@@ -255,8 +264,6 @@ bool Camera::is_current() const {
return get_viewport()->get_camera() == this;
} else
return current;
-
- return false;
}
bool Camera::_can_gizmo_scale() const {
@@ -694,6 +701,7 @@ Camera::Camera() {
near = 0;
far = 0;
current = false;
+ viewport = NULL;
force_change = false;
mode = PROJECTION_PERSPECTIVE;
set_perspective(70.0, 0.05, 100.0);
diff --git a/scene/3d/camera.h b/scene/3d/camera.h
index cbcefbb0ae..1cd729199d 100644
--- a/scene/3d/camera.h
+++ b/scene/3d/camera.h
@@ -64,6 +64,7 @@ public:
private:
bool force_change;
bool current;
+ Viewport *viewport;
Projection mode;