From 7e0f4bcbf0f4717145d8beac40d52e3acebbe2aa Mon Sep 17 00:00:00 2001 From: Joshua Yanovski Date: Wed, 29 Jul 2020 21:10:20 +0200 Subject: [PATCH] Fix crash in edge case for pixel art. --- voxygen/src/ui/graphic/pixel_art.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/voxygen/src/ui/graphic/pixel_art.rs b/voxygen/src/ui/graphic/pixel_art.rs index f3994b4375..fa32f569fd 100644 --- a/voxygen/src/ui/graphic/pixel_art.rs +++ b/voxygen/src/ui/graphic/pixel_art.rs @@ -47,7 +47,7 @@ pub fn resize_pixel_art(image: &RgbaImage, new_width: u32, new_height: u32) -> R for x in 0..new_width { // Calculate sampling strategy let xsmin = x as f32 * wratio; - let xsmax = xsmin + wratio; + let xsmax = (xsmin + wratio).min(width as f32); // Min and max pixels covered let xminp = xsmin.floor() as u32; let xmaxp = ((xsmax - EPSILON).ceil() as u32) @@ -63,7 +63,7 @@ pub fn resize_pixel_art(image: &RgbaImage, new_width: u32, new_height: u32) -> R for y in 0..new_height { // Calculate sampling strategy let ysmin = y as f32 * hratio; - let ysmax = ysmin + hratio; + let ysmax = (ysmin + hratio).min(height as f32); // Min and max of pixels covered let yminp = ysmin.floor() as u32; let ymaxp = ((ysmax - EPSILON).ceil() as u32)