fix: crash when entering right tunnel due to overflowing pixel position calculation

This commit is contained in:
2025-08-11 15:44:04 -05:00
parent dbafa17670
commit d099e514a1

View File

@@ -2,10 +2,9 @@ use glam::{IVec2, UVec2};
use sdl2::rect::Rect; use sdl2::rect::Rect;
pub fn centered_with_size(pixel_pos: IVec2, size: UVec2) -> Rect { pub fn centered_with_size(pixel_pos: IVec2, size: UVec2) -> Rect {
Rect::new( // Ensure the position doesn't cause integer overflow when centering
pixel_pos.x - size.x as i32 / 2, let x = pixel_pos.x.saturating_sub(size.x as i32 / 2);
pixel_pos.y - size.y as i32 / 2, let y = pixel_pos.y.saturating_sub(size.y as i32 / 2);
size.x,
size.y, Rect::new(x, y, size.x, size.y)
)
} }