From cf50eb130e33f55f07466f4e1805c7d3395e5522 Mon Sep 17 00:00:00 2001 From: kobewi Date: Thu, 23 Feb 2023 23:21:50 +0100 Subject: Fix custom viewports in Camera2D --- scene/2d/camera_2d.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'scene/2d') diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index f7d2ae7d2d..2b90a3702f 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -414,15 +414,19 @@ Camera2D::Camera2DProcessCallback Camera2D::get_process_callback() const { } void Camera2D::_make_current(Object *p_which) { + if (!viewport || (custom_viewport && !ObjectDB::get_instance(custom_viewport_id))) { + return; + } + if (p_which == this) { if (is_inside_tree()) { - get_viewport()->_camera_2d_set(this); + viewport->_camera_2d_set(this); queue_redraw(); } } else { if (is_inside_tree()) { - if (get_viewport()->get_camera_2d() == this) { - get_viewport()->_camera_2d_set(nullptr); + if (viewport->get_camera_2d() == this) { + viewport->_camera_2d_set(nullptr); } queue_redraw(); } @@ -449,7 +453,7 @@ void Camera2D::make_current() { void Camera2D::clear_current() { ERR_FAIL_COND(!is_current()); - if (viewport && !(custom_viewport && !ObjectDB::get_instance(custom_viewport_id))) { + if (viewport && !(custom_viewport && !ObjectDB::get_instance(custom_viewport_id)) && viewport->is_inside_tree()) { viewport->assign_next_enabled_camera_2d(group_name); } } -- cgit v1.2.3