Clamp the demo canvas to maxTextureDimension2D - #51
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 formaxTextureDimension2D, which is 8192 by default and which this demo never raises (it only requestsmaxComputeWorkgroupStorageSize). 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:
The fix
resizeCanvasnow derives the scale so neither dimension can exceed the limit.dprremains 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:
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]vsx[199..2680] y[548..1251]. Worth a separate issue.🤖 Generated with Claude Code