Skip to content

Clamp the demo canvas to maxTextureDimension2D - #51

Merged
jowens merged 1 commit into
mainfrom
fix-demo-canvas-limit
Aug 31, 2026
Merged

Clamp the demo canvas to maxTextureDimension2D#51
jowens merged 1 commit into
mainfrom
fix-demo-canvas-limit

Conversation

@jowens

@jowens jowens commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Fixes a black screen introduced by #49, reported by @jowens on Chrome 151 / macOS.

What happened

#49 made the canvas backing store devicePixelRatio-scaled, capped at 2x. It did not account for maxTextureDimension2D, which is 8192 by default and which this demo never raises (it only requests maxComputeWorkgroupStorageSize). Once either dimension crosses that limit the swap-chain texture is invalid and nothing renders — a black canvas with the controls still drawn on top, and no exception to notice.

Because the DPR multiplies the CSS size, on any Retina display a window wider than 4096 CSS pixels crosses the limit. Before #49 the backing store was the CSS size, so it would have taken an 8192px-wide window.

Measured at a 4500x1000 viewport, dpr 2:

canvas backing result
before #49 4500x1000 particles render
after #49 9000x2000 nothing drawn
this fix 8192x1820 particles render

The fix

resizeCanvas now derives the scale so neither dimension can exceed the limit. dpr remains the true CSS-to-backing-store ratio after clamping, which matters because pointer coordinates and the influence radius are converted with it.

Normal window sizes are unaffected and still get the full 2x — 1440x900 still gives 2880x1800. Verified across 1280x480, 1440x900, 3000x1200, 4500x1000 and 6000x1400: all render, none exceed the limit.

Regression guard

The demo smoke test added in #49 ran at the default window size, nowhere near large enough to catch this. It now also loads the demo at 5000x1000 and asserts the backing store stays within the device limit.

Verified it fails with the clamp removed:

- canvas 10000x2000 exceeds maxTextureDimension2D 8192 at a 5000x1000 viewport; the demo will render black

Unrelated pre-existing issue, noted not fixed

While measuring this I found the particles only occupy a horizontal band — roughly 86% of the width but 40% of the height, vertically centred. That is not from #49: it measures identically on 4bed4b3 (pre-#49), x[198..2685] y[545..1255] vs x[199..2680] y[548..1251]. Worth a separate issue.

🤖 Generated with Claude Code

Fixes a black screen introduced by #49.

That PR made the canvas backing store devicePixelRatio-scaled, capped at
2x. It did not account for maxTextureDimension2D, which is 8192 by
default and which this demo never raises. Once either dimension crosses
it the swap-chain texture is invalid and nothing renders at all: a black
canvas with the controls still drawn on top, and no exception to notice.

Because the DPR multiplies the CSS size, on any Retina display a window
wider than 4096 CSS pixels crosses the limit. Before #49 the backing
store was the CSS size, so it would have taken an 8192px-wide window.

Measured at a 4500x1000 viewport, dpr 2:

  before #49  canvas 4500x1000  particles render
  after  #49  canvas 9000x2000  nothing drawn
  this fix    canvas 8192x1820  particles render

resizeCanvas now derives the scale so neither dimension can exceed the
limit, and dpr remains the true CSS-to-backing-store ratio after
clamping, since pointer coordinates and the influence radius are
converted with it. Normal window sizes are unaffected and still get the
full 2x: 1440x900 gives 2880x1800 as before.

Also adds a regression guard to the demo smoke test. The existing checks
ran at the default window size, nowhere near large enough to see this,
so the guard loads the demo at 5000x1000 and asserts the backing store
stays within the device limit. Verified it fails with the clamp removed:
"canvas 10000x2000 exceeds maxTextureDimension2D 8192".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jowens
jowens merged commit cd07bef into main Aug 31, 2026
2 checks passed
@jowens
jowens deleted the fix-demo-canvas-limit branch August 31, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant