fix(web): cap canvas via Window resize_constraints (real surface fix) #100
Reference in New Issue
Block a user
Delete Branch "fix/web-canvas-resize-constraints"
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?
Why the earlier attempts failed
#97/#98 set
max-widthon a wrapper element and relied on the canvasswidth: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 winitset_max_inner_size→ the canvass ownmax-width/max-heightstyle — the canonical mechanism for bounding the surface. So the surface can never exceed wgpus downlevel_webgl2max_texture_dimension_2d` (2048).play.htmlmirrors the samemax-*directly on #bevy-canvas (belt-and-suspenders) and centres the letterbox withmargin:auto; the obsolete wrapper + clamp script are removed.Deploy note
lib.rs is a wasm-feeding change, so
web-wasm-rebuildregeneratescanvas_bg.wasmafter 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
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>