From 0f18f225ee97e95cca9ef0c7e19e08600c26dd7e Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Wed, 6 Oct 2021 13:41:21 +0800 Subject: [PATCH] Fix crash when deleting Camera2D and Viewport assigned to it --- scene/2d/camera_2d.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index c87ebbcc736..f93b7b0db8a 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -259,12 +259,13 @@ void Camera2D::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { + const bool viewport_valid = !custom_viewport || ObjectDB::get_instance(custom_viewport_id); if (is_current()) { - if (viewport && !(custom_viewport && !ObjectDB::get_instance(custom_viewport_id))) { + if (viewport && viewport_valid) { viewport->set_canvas_transform(Transform2D()); } } - if (viewport) { + if (viewport && viewport_valid) { viewport->disconnect("size_changed", this, "_update_scroll"); } remove_from_group(group_name);