How to know when all imageIds have been prefetched CornerstoneTools

Describe Your Question

When attempting to annotate on a viewport prior to all images being pre fetched an error is thrown and annotations are not possible on any viewport without a page refresh from that point. This is an edge case issue, but I am hoping to disable annotations until all data is pre fetched and then enable annotations at that point.

Here is the error:

Uncaught TypeError: Cannot destructure property 'preScale' of 'viewport.getImageData(...)' as it is undefined.
    at isViewportPreScaled (isViewportPreScaled.ts:17:1)
    at RectangleROITool.renderAnnotation (RectangleROITool.ts:772:1)
    at handleDrawSvg (triggerAnnotationRender.ts:188:1)
    at Array.forEach (<anonymous>)
    at eval (triggerAnnotationRender.ts:202:1)
    at draw (draw.ts:10:1)
    at AnnotationRenderingEngine._triggerRender (triggerAnnotationRender.ts:184:1)
    at AnnotationRenderingEngine._renderFlaggedViewports (triggerAnnotationRender.ts:93:1)

What steps can we follow to reproduce the bug?

  1. Annotation tool active on mouse (rectangle, probe etc…)
  2. Load page and draw annotation prior to all series loading

Welcome to the forum @Littlewoko!

It is not clear why this is exception is happening because if we look at line 17 in isViewportPreScaled.ts we will see that there is already as check for an undefined viewport.getImageData(). Furthermore, I was NOT able to reproduce this problem.

Perhaps as a sanity check, have at cache.getImageLoadObject (with your image id) and determine if the image object is actually cached?