Skip to content

Commit

Permalink
fix: referenceId and Synchronizer - Improve error handling and code r…
Browse files Browse the repository at this point in the history
…obustness (#1612)

-  Removed unused focalPoint parameter from the volumeId query string construction in `BaseVolumeViewport.ts`.
-  Added a check for `eventSource` in `Synchronizer.ts` to prevent errors when it is undefined.
-  Updated error handling in `Synchronizer.ts` to return null instead of throwing an error when `RenderingEngine` or `viewport` is not found.
-  Ensured that `viewport.element` is returned safely by checking for the existence of the viewport.
  • Loading branch information
sedghi authored Nov 22, 2024
1 parent 48de11f commit 32417a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/RenderingEngine/BaseVolumeViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@ abstract class BaseVolumeViewport extends Viewport {
const querySeparator = volumeId.includes('?') ? '&' : '?';
return `volumeId:${volumeId}${querySeparator}sliceIndex=${sliceIndex}&viewPlaneNormal=${viewPlaneNormal.join(
','
)}&focalPoint=${focalPoint.join(',')}`;
)}`;
}

private _addVolumeId(volumeId: string): void {
Expand Down
13 changes: 11 additions & 2 deletions packages/tools/src/store/SynchronizerManager/Synchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ class Synchronizer {

viewports.forEach((vp) => {
const eventSource = this.getEventSource(vp);

if (!eventSource) {
return;
}

eventSource.removeEventListener(
Enums.Events.ELEMENT_DISABLED,
disableHandler
Expand All @@ -380,9 +385,13 @@ class Synchronizer {
const { renderingEngineId, viewportId } = viewportInfo;
const renderingEngine = getRenderingEngine(renderingEngineId);
if (!renderingEngine) {
throw new Error(`No RenderingEngine for Id: ${renderingEngineId}`);
return null;
}
const viewport = renderingEngine.getViewport(viewportId);
if (!viewport) {
return null;
}
return renderingEngine.getViewport(viewportId).element;
return viewport.element;
}
}

Expand Down

0 comments on commit 32417a5

Please sign in to comment.