fix(web): cap canvas via Window resize_constraints (real surface fix) #100

Merged
funman300 merged 1 commits from fix/web-canvas-resize-constraints into master 2026-06-24 01:59:37 +00:00
Owner

Why the earlier attempts failed

#97/#98 set max-width on a wrapper element and relied on the canvass width:100%resolving against it. But winit observes and sizes the **canvas element itself** (ResizeObserver on its content box) — so the wrapper cap never reached the wgpu surface, and/play` still panicked at 2560x1440 on a 4K@150% viewport (confirmed: same error on a fresh, uncached load).

The actual fix

Set the primary Windows **resize_constraints { max_width: 2048, max_height: 2048 }** (solitaire_web/src/lib.rs). On web, Bevy maps this to winit set_max_inner_size → the canvass own max-width/max-height style — the canonical mechanism for bounding the surface. So the surface can never exceed wgpus downlevel_webgl2 max_texture_dimension_2d` (2048).

play.html mirrors the same max-* directly on #bevy-canvas (belt-and-suspenders) and centres the letterbox with margin:auto; the obsolete wrapper + clamp script are removed.

Deploy note

lib.rs is a wasm-feeding change, so web-wasm-rebuild regenerates canvas_bg.wasm after merge, then docker-build redeploys — ~20-30 min on the serial runner. Rhys should test on a fresh URL (?v=3) once it lands.

🤖 Generated with Claude Code

## Why the earlier attempts failed #97/#98 set `max-width` on a **wrapper** element and relied on the canvas`s `width:100%` resolving against it. But winit observes and sizes the **canvas element itself** (ResizeObserver on its content box) — so the wrapper cap never reached the wgpu surface, and `/play` still panicked at 2560x1440 on a 4K@150% viewport (confirmed: same error on a fresh, uncached load). ## The actual fix Set the primary Window`s **`resize_constraints { max_width: 2048, max_height: 2048 }`** (solitaire_web/src/lib.rs). On web, Bevy maps this to winit `set_max_inner_size` → the canvas`s own `max-width`/`max-height` style — the canonical mechanism for bounding the surface. So the surface can never exceed wgpu`s downlevel_webgl2 `max_texture_dimension_2d` (2048). `play.html` mirrors the same `max-*` **directly on #bevy-canvas** (belt-and-suspenders) and centres the letterbox with `margin:auto`; the obsolete wrapper + clamp script are removed. ## Deploy note lib.rs is a wasm-feeding change, so `web-wasm-rebuild` regenerates `canvas_bg.wasm` after merge, then docker-build redeploys — ~20-30 min on the serial runner. Rhys should test on a fresh URL (`?v=3`) once it lands. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
funman300 added 1 commit 2026-06-24 01:59:27 +00:00
The previous attempts (#97/#98) capped a wrapper element's max-width and
relied on the canvas's width:100% resolving against it — but winit observes
and sizes the *canvas element itself* (via ResizeObserver on its content box),
so the wrapper cap never reached the surface and /play still panicked at
2560x1440 on a 4K@150% viewport.

Use the canonical mechanism instead: set the primary Window's
`resize_constraints { max_width: 2048, max_height: 2048 }`. On web, Bevy maps
this to winit `set_max_inner_size` → the canvas's own `max-width`/`max-height`
style, so the wgpu surface can never exceed wgpu's downlevel_webgl2
max_texture_dimension_2d (2048). play.html mirrors the same `max-*` directly on
#bevy-canvas (belt-and-suspenders) and centres the letterbox with margin:auto;
the obsolete wrapper + clamp script are removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
funman300 merged commit 56e05caaa9 into master 2026-06-24 01:59:37 +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#100