From b89befe17312ed99e5b6c0e2f2644c1b2eb64e56 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Thu, 31 Mar 2022 16:42:14 +0800 Subject: [PATCH] Fix crash when using Camera2D::set_custom_viewport() --- scene/2d/camera_2d.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index cb8577dd264..f93b16da348 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -583,6 +583,10 @@ void Camera2D::set_custom_viewport(Node *p_viewport) { remove_from_group(canvas_group_name); } + if (custom_viewport && !ObjectDB::get_instance(custom_viewport_id)) { + viewport = nullptr; + } + custom_viewport = Object::cast_to(p_viewport); if (custom_viewport) {