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.
This commit is contained in:
Omar Emara
2024-01-18 12:34:55 +02:00
parent baab14ca38
commit 5309d1c574
2 changed files with 14 additions and 4 deletions

View File

@@ -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

View File

@@ -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