Skip to content

[Bug] Viewport .setDisplayArea when CPU rendering is used throws an error. #2343

@jmannau

Description

@jmannau

Describe the Bug

When Cornerstone is using CPU rendering and a StackViewport is used, calling .setDisplayArea throws an error and the viewport is not updated.

The error thrown is:

StackViewport.js:812 Uncaught TypeError: Cannot destructure property 'focalPoint' of 'cameraInterface' as it is undefined.
    at StackViewport.setCameraCPU (StackViewport.js:812:17)
    at StackViewport.setDisplayArea (Viewport.js:391:14)
    at initializeCornerstone (cornerstoneUtils.js:61:12)
    at async cs-cpu.js:5:18

A reproduction repository is available here https://github.com/jmannau/cs-cpu-bug

In this Repo are 2 examples, c3d-gpu.html which is the default using GPU/WebGL rendering and c3d-cpu.html where CPU rendering is enabled.

When viewing c3d-gpu.html the image is loaded correctly and resized/repositioned correctly.

Image

When viewing c3d-cpu.html the image is loaded, but not resized/repositioned as an error is thrown.\

Image

Steps to Reproduce

  1. Initialise Cornerstone with CPU rendering
  2. Create a StackViewport
  3. Load a image stack
  4. Call .setDisplayArea to resize/reposition the image in the viewport.

The issue appears to be here

this.setCamera(this.fitToCanvasCamera);

where fitToCanvasCamera is undefined for CPU Viewports.

From the look of it. .setFitToCanvasCamera is called in Viewport resetCamera

this.setFitToCanvasCamera(this.getCamera());
but StackViewport overrides resetCamera and resetCameraCPU doesn't set fitToCanvasCamera

The current behavior

When using CPU rendering, it is not possible to resize the viewport using .setDisplayArea

The expected behavior

CPU rendering should match GPU rendering and .setDisplayArea should not throw.

System Information

  System:
    OS: macOS 15.6.1
    CPU: (14) arm64 Apple M4 Max
    Memory: 572.66 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.18.0 - ~/.n/bin/node
    Yarn: 1.22.22 - ~/.n/bin/yarn
    npm: 10.9.3 - ~/.n/bin/npm
    bun: 1.1.38 - /opt/homebrew/bin/bun
  Browsers:
    Brave Browser: 140.1.82.170
    Chrome: 140.0.7339.185
    Safari: 18.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsSomething isn't working, verified by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions