Skip to content

[Bug] resize() in ContextPool mode skips renderer sub-rect/camera recompute when a render frame is queued → stale canvasToWorld #645

Description

@gpillajo-lang

Describe the bug

In ContextPool rendering mode (default in 4.x), calling renderingEngine.resize() while a render frame is already queued leaves viewports inconsistent: canvasToWorld() returns coordinates from a mixed state — the canvas is re-measured (new size) but the renderer's offscreen sub-rectangle and the camera are NOT recomputed.

In ContextPoolRenderingEngine._resizeVTKViewports, sWidth/sHeight are updated, but the function early-returns when _animationFrameSet === true, before calling _resize(...) (recomputes the context max size and each renderer's viewport sub-rect) and before the camera loop (resetCameraForResize() + setCamera(prevCamera)).

So canvasToWorld([x,y]) of an ORTHOGRAPHIC viewport returns wrong world coords for one or more frames after a resize (e.g. toggling a CSS fullscreen layout), until a later "clean" resize (no queued frame) completes the recompute. Intermittent — depends on whether a frame is queued at resize time.

Steps to reproduce

  1. RenderingEngine in ContextPool mode, several ORTHOGRAPHIC viewports sharing a context.
  2. Render them (sets _animationFrameSet = true).
  3. Change CSS layout so a viewport element resizes (maximize/restore a grid cell) and call renderingEngine.resize(true, false) in the same tick.
  4. Read viewport.canvasToWorld([0,0]) right after.

Expected: after resize(), canvasToWorld reflects the new canvas size AND the recomputed sub-rect/camera consistently.
Actual: it mixes new canvas.width/height with the old renderer sub-rect → off until a later resize without a queued frame.

Environment: @cornerstonejs/core 4.22.13 · ContextPool (default) · ORTHOGRAPHIC viewports (NIfTI volume) · WebGL2 · Chrome/Windows.

Code pointer: RenderingEngine/ContextPoolRenderingEngine.js → _resizeVTKViewports: the if (this._animationFrameSet) return; runs after sWidth/sHeight are set but before _resize() and the camera recompute.

Workaround: re-measure on a later frame (double requestAnimationFrame + a setTimeout fallback); avoid deriving persistent geometry from canvasToWorld right after a layout change.

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions