From 2481208f3177a1f0cada3470adacfafab66689d7 Mon Sep 17 00:00:00 2001 From: Abhijith Sb <105038248+abhijith-trenser@users.noreply.github.com> Date: Wed, 5 Nov 2025 20:41:26 +0530 Subject: [PATCH] Fix : Problems related to measurement operation undo (#5541) fixed the console error while undoing a removed annotation --- .../cornerstone/src/initMeasurementService.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/extensions/cornerstone/src/initMeasurementService.ts b/extensions/cornerstone/src/initMeasurementService.ts index d66ef291b..93eabddd5 100644 --- a/extensions/cornerstone/src/initMeasurementService.ts +++ b/extensions/cornerstone/src/initMeasurementService.ts @@ -503,11 +503,15 @@ const connectMeasurementServiceToTools = ({ } const removedAnnotation = annotation.state.getAnnotation(removedMeasurementId); removeAnnotation(removedMeasurementId); - commandsManager.run('triggerCreateAnnotationMemo', { - annotation: removedAnnotation, - FrameOfReferenceUID: removedAnnotation.metadata.FrameOfReferenceUID, - options: { deleting: true }, - }); + // Ensure `removedAnnotation` is available before triggering the memo, + // as it can be undefined during an undo operation + if (removedAnnotation) { + commandsManager.run('triggerCreateAnnotationMemo', { + annotation: removedAnnotation, + FrameOfReferenceUID: removedAnnotation.metadata.FrameOfReferenceUID, + options: { deleting: true }, + }); + } const renderingEngine = cornerstoneViewportService.getRenderingEngine(); // Note: We could do a better job by triggering the render on the // viewport itself, but the removeAnnotation does not include that info...