Skip to content

Commit 4eabbb7

Browse files
Fix u32 overflow when window is resize (#21365)
# Objective bevy v0.17.1, archlinux + i3wm. `cargo run --example 2d_viewport_to_world` ``` thread 'Compute Task Pool (1)' (470531) panicked at /home/go/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/glam-0.30.8/src/u32/uvec2.rs:1071:23: attempt to subtract with overflow note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace Encountered a panic in system `2d_viewport_to_world::controls`! Encountered a panic in system `bevy_app::main_schedule::FixedMain::run_fixed_main`! Encountered a panic in system `bevy_time::fixed::run_fixed_main_schedule`! Encountered a panic in system `bevy_app::main_schedule::Main::run_main`! ``` ## Solution Consider window resize。 ## Testing no panic. ---
1 parent 9227946 commit 4eabbb7

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

examples/2d/2d_viewport_to_world.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ fn controls(
7777
}
7878

7979
if let Some(viewport) = camera.viewport.as_mut() {
80+
// Reset viewport size on window resize
81+
if viewport.physical_size.x > window_size.x || viewport.physical_size.y > window_size.y {
82+
viewport.physical_size = (window_size.as_vec2() * 0.75).as_uvec2();
83+
}
84+
8085
// Viewport movement controls
8186
if input.pressed(KeyCode::KeyW) {
8287
viewport.physical_position.y = viewport.physical_position.y.saturating_sub(uspeed);

0 commit comments

Comments
 (0)