fix(web): clamp wgpu surface to CSS pixels on HiDPI to prevent wasm panic
Root cause: fit_canvas_to_parent requests a wgpu surface sized in physical pixels (CSS pixels × devicePixelRatio). On HiDPI displays (DPR ≈ 2) the physical size (e.g. 2612×1469) exceeds WebGL2's per- dimension texture limit of 2048, triggering a wgpu validation panic that kills the WASM thread immediately on the first window resize. Fix: add `resolution: WindowResolution::default().with_scale_factor_override(1.0)` to the primary window so Bevy uses CSS/logical pixels as the surface dimensions. For a 1306×734 CSS viewport this keeps the framebuffer well within 2048 regardless of devicePixelRatio. Also remove the temporary [drag] console logging added in the previous commit — the panic was causing drag to never run, not a hit-test bug. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ use bevy::asset::AssetMetaCheck;
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::RenderPlugin;
|
||||
use bevy::render::settings::{RenderCreation, WgpuSettings, WgpuSettingsPriority};
|
||||
use bevy::window::{Window, WindowPlugin};
|
||||
use bevy::window::{Window, WindowPlugin, WindowResolution};
|
||||
use solitaire_data::LocalOnlyProvider;
|
||||
use solitaire_engine::CoreGamePlugin;
|
||||
use wasm_bindgen::prelude::*;
|
||||
@@ -34,6 +34,14 @@ pub fn start() {
|
||||
fit_canvas_to_parent: true,
|
||||
// Prevent the browser stealing keyboard events and scroll.
|
||||
prevent_default_event_handling: true,
|
||||
// Force scale_factor = 1.0 so the wgpu surface is sized in
|
||||
// CSS/logical pixels rather than physical pixels. Without this,
|
||||
// HiDPI displays (devicePixelRatio ≥ 2) produce a framebuffer
|
||||
// whose physical width can exceed WebGL2's 2048-pixel per-
|
||||
// dimension limit, causing a wgpu validation panic on the first
|
||||
// resize event and killing the WASM thread.
|
||||
resolution: WindowResolution::default()
|
||||
.with_scale_factor_override(1.0),
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
|
||||
Reference in New Issue
Block a user