fix(web): clamp /play canvas to GPU MAX_TEXTURE_SIZE (wgpu 2048 panic) #97

Merged
funman300 merged 1 commits from fix/web-canvas-max-texture-size into master 2026-06-24 00:45:30 +00:00
Owner

Problem

Rhys gets a fatal wgpu panic loading /play on a 1440p display:

Surface::configure ... Requested was (2560, 1440), maximum extent for either dimension is 2048

WebGL2's MAX_TEXTURE_SIZE is only 2048 on many laptop/integrated GPUs. fit_canvas_to_parent sizes 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 earlier scale_factor_override(1.0) fix only neutralised HiDPI (CSS × devicePixelRatio); it doesn't help when the logical viewport already exceeds 2048.

Fix (play.html only)

Wrap the canvas in #bevy-wrap and, before init, clamp that element's max-width/max-height to the device's real gl.MAX_TEXTURE_SIZE (fallback: the 2048 WebGL2 floor). fit_canvas_to_parent then never requests a surface larger than the GPU allows.

  • Devices at the 2048 floor (Rhys's) render ≤2048 and letterbox, centered — no crash.
  • GPUs reporting 4096/8192 are unaffected and still fill the viewport.

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: /play should 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

## Problem Rhys gets a fatal wgpu panic loading `/play` on a 1440p display: ``` Surface::configure ... Requested was (2560, 1440), maximum extent for either dimension is 2048 ``` WebGL2's `MAX_TEXTURE_SIZE` is only **2048** on many laptop/integrated GPUs. `fit_canvas_to_parent` sizes 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 earlier `scale_factor_override(1.0)` fix only neutralised HiDPI (CSS × devicePixelRatio); it doesn't help when the **logical** viewport already exceeds 2048. ## Fix (`play.html` only) Wrap the canvas in `#bevy-wrap` and, before init, clamp that element's `max-width`/`max-height` to the device's **real** `gl.MAX_TEXTURE_SIZE` (fallback: the 2048 WebGL2 floor). `fit_canvas_to_parent` then never requests a surface larger than the GPU allows. - Devices at the 2048 floor (Rhys's) render ≤2048 and letterbox, centered — no crash. - GPUs reporting 4096/8192 are unaffected and still fill the viewport. ## 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: `/play` should 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](https://claude.com/claude-code)
funman300 added 1 commit 2026-06-24 00:45:03 +00:00
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>
funman300 merged commit b3b282ec2d into master 2026-06-24 00:45:30 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: funman300/Ferrous-Solitaire#97