fix(web): clamp /play canvas to GPU MAX_TEXTURE_SIZE (wgpu 2048 panic) #97
Reference in New Issue
Block a user
Delete Branch "fix/web-canvas-max-texture-size"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Rhys gets a fatal wgpu panic loading
/playon a 1440p display:WebGL2's
MAX_TEXTURE_SIZEis only 2048 on many laptop/integrated GPUs.fit_canvas_to_parentsizes the wgpu surface to the canvas's parent (the full viewport), so a 2560-wide viewport configures a 2560-wide surface → validation error → the WASM thread dies on the first frame. The earlierscale_factor_override(1.0)fix only neutralised HiDPI (CSS × devicePixelRatio); it doesn't help when the logical viewport already exceeds 2048.Fix (
play.htmlonly)Wrap the canvas in
#bevy-wrapand, before init, clamp that element'smax-width/max-heightto the device's realgl.MAX_TEXTURE_SIZE(fallback: the 2048 WebGL2 floor).fit_canvas_to_parentthen never requests a surface larger than the GPU allows.Verification
⚠️ I cannot browser-test this here (no GPU/WebGL). The logic is sound and pairs with the existing scale-factor fix, but it needs a real-browser check on a 1440p (or 2048-limited) display:
/playshould load and render (letterboxed if the GPU max is 2048) instead of panicking. Worth confirming on Rhys's machine before relying on it.No wasm rebuild needed (HTML-only change).
🤖 Generated with Claude Code
Rhys hit a fatal wgpu validation panic loading /play on a 1440p display: Surface::configure ... Requested was (2560, 1440), maximum extent for either dimension is 2048 The earlier scale_factor_override(1.0) fix only neutralised HiDPI (CSS×DPR); it didn't help when the *logical* viewport itself exceeds 2048. `fit_canvas_to_ parent` sizes the wgpu surface to the canvas's parent, so a 2560-wide viewport configures a 2560-wide surface — past WebGL2's 2048 per-dimension limit on laptop/integrated GPUs, and the panic kills the WASM thread on the first frame. Wrap the canvas in #bevy-wrap and, before init, clamp that element's max- width/height to the device's actual gl.MAX_TEXTURE_SIZE (falling back to the 2048 WebGL2 floor). fit_canvas_to_parent then never produces a surface larger than the GPU allows. Only devices at the 2048 floor letterbox (centered); GPUs that report 4096/8192 still fill the viewport. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>