From 5309d1c5748b5ecbbfaa72a0c7ce9d2caeb70fca Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Thu, 18 Jan 2024 12:34:55 +0200 Subject: [PATCH] Fix: Crash in Defocus node when no camera exist The Defocus node crashes when no camera exist in the scene. We fix this by defaulting to a focus distance of 10 when a camera doesn't exist. --- .../operations/COM_ConvertDepthToRadiusOperation.cc | 9 +++++++-- .../nodes/composite/nodes/node_composite_defocus.cc | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cc b/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cc index 7e8daa0a342..c23ba17da3e 100644 --- a/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cc +++ b/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cc @@ -155,10 +155,15 @@ float ConvertDepthToRadiusOperation::get_focal_length() const return camera ? math::max(1e-6f, camera->lens / 1000.0f) : 50.0f / 1000.0f; } -/* Computes the distance to the point that is completely in focus. */ +/* Computes the distance to the point that is completely in focus. Default to 10 meters for null + * camera. */ float ConvertDepthToRadiusOperation::compute_focus_distance() const { - return BKE_camera_object_dof_distance(get_camera_object()); + const Object *camera_object = get_camera_object(); + if (!camera_object) { + return 10.0f; + } + return BKE_camera_object_dof_distance(camera_object); } /* Computes the number of pixels per meter of the sensor size. This is essentially the resolution diff --git a/source/blender/nodes/composite/nodes/node_composite_defocus.cc b/source/blender/nodes/composite/nodes/node_composite_defocus.cc index 1d012b7405f..340d01e8096 100644 --- a/source/blender/nodes/composite/nodes/node_composite_defocus.cc +++ b/source/blender/nodes/composite/nodes/node_composite_defocus.cc @@ -275,10 +275,15 @@ class DefocusOperation : public NodeOperation { return camera ? math::max(1e-6f, camera->lens / 1000.0f) : 50.0f / 1000.0f; } - /* Computes the distance to the point that is completely in focus. */ + /* Computes the distance to the point that is completely in focus. Default to 10 meters for null + * camera. */ float compute_focus_distance() { - return BKE_camera_object_dof_distance(get_camera_object()); + const Object *camera_object = get_camera_object(); + if (!camera_object) { + return 10.0f; + } + return BKE_camera_object_dof_distance(camera_object); } /* Computes the number of pixels per meter of the sensor size. This is essentially the resolution