From 2b4a95a4a981e3ae0054a0f8d36d6222f11f823b Mon Sep 17 00:00:00 2001 From: Corwin Date: Sat, 6 Aug 2022 01:03:51 +0100 Subject: [PATCH] clamp the position before converting to u8 --- agb/src/display/window.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/agb/src/display/window.rs b/agb/src/display/window.rs index 87a5ffe7..92c5ef7e 100644 --- a/agb/src/display/window.rs +++ b/agb/src/display/window.rs @@ -2,7 +2,7 @@ use agb_fixnum::Rect; use crate::memory_mapped::MemoryMapped; -use super::{tiled::BackgroundID, DISPLAY_CONTROL}; +use super::{tiled::BackgroundID, DISPLAY_CONTROL, HEIGHT, WIDTH}; pub struct Windows { wins: [MovableWindow; 2], @@ -188,7 +188,11 @@ impl MovableWindow { pub fn set_position(&mut self, rect: &Rect) -> &mut Self { let new_rect = Rect::new( - (rect.position.x as u8, rect.position.y as u8).into(), + ( + rect.position.x.clamp(0, WIDTH) as u8, + rect.position.y.clamp(0, HEIGHT) as u8, + ) + .into(), (rect.size.x as u8, rect.size.y as u8).into(), ); self.set_position_u8(new_rect)