From b3df34b4059b578a65900217bb9da7df5dd40039 Mon Sep 17 00:00:00 2001 From: Xevion Date: Mon, 11 Aug 2025 15:44:04 -0500 Subject: [PATCH] fix: crash when entering right tunnel due to overflowing pixel position calculation --- src/helpers.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index 92a19c6..4205194 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -2,10 +2,9 @@ use glam::{IVec2, UVec2}; use sdl2::rect::Rect; pub fn centered_with_size(pixel_pos: IVec2, size: UVec2) -> Rect { - Rect::new( - pixel_pos.x - size.x as i32 / 2, - pixel_pos.y - size.y as i32 / 2, - size.x, - size.y, - ) + // Ensure the position doesn't cause integer overflow when centering + let x = pixel_pos.x.saturating_sub(size.x as i32 / 2); + let y = pixel_pos.y.saturating_sub(size.y as i32 / 2); + + Rect::new(x, y, size.x, size.y) }