From 6d03b17c00ce961f786c25833deaeb25e4f51a10 Mon Sep 17 00:00:00 2001 From: Ibrahim <93064150+IbrahimCSAE@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:19:27 -0500 Subject: [PATCH] fix(camera): don't try to access renderer if it's undefined (#1674) --- packages/core/src/RenderingEngine/Viewport.ts | 5 +++++ packages/core/src/RenderingEngine/VolumeViewport.ts | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/packages/core/src/RenderingEngine/Viewport.ts b/packages/core/src/RenderingEngine/Viewport.ts index 0f45996d0e..f01f80680a 100644 --- a/packages/core/src/RenderingEngine/Viewport.ts +++ b/packages/core/src/RenderingEngine/Viewport.ts @@ -1301,6 +1301,11 @@ class Viewport { protected getVtkActiveCamera(): vtkCamera | vtkSlabCamera { const renderer = this.getRenderer(); + if (!renderer) { + console.warn('No renderer found for the viewport'); + return null; + } + return renderer.getActiveCamera(); } diff --git a/packages/core/src/RenderingEngine/VolumeViewport.ts b/packages/core/src/RenderingEngine/VolumeViewport.ts index 03ba3dbf0f..259287c774 100644 --- a/packages/core/src/RenderingEngine/VolumeViewport.ts +++ b/packages/core/src/RenderingEngine/VolumeViewport.ts @@ -203,6 +203,12 @@ class VolumeViewport extends BaseVolumeViewport { protected setCameraClippingRange() { const activeCamera = this.getVtkActiveCamera(); + + if (!activeCamera) { + console.warn('No active camera found'); + return; + } + if (activeCamera.getParallelProjection()) { // which makes more sense. However, in situations like MPR where the camera is // oblique, the slab thickness might not be sufficient.