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
- RenderingEngine in ContextPool mode, several ORTHOGRAPHIC viewports sharing a context.
- Render them (sets _animationFrameSet = true).
- Change CSS layout so a viewport element resizes (maximize/restore a grid cell) and call renderingEngine.resize(true, false) in the same tick.
- 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.
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
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.