From 127abbea770e1fff660b0ffd10ab58bcb46bf0af Mon Sep 17 00:00:00 2001 From: mamg22 <45301823+mamg22@users.noreply.github.com> Date: Tue, 30 Nov 2021 19:52:09 -0400 Subject: fix crash when zooming out on small images (#178) When rendering images, destination image width and height may become zero due to float-to-int conversion after zoom calculation, later crashing when creating an image using those dimensions. This sets a minimum of 1 to both variables. Closes #82 --- image.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'image.c') diff --git a/image.c b/image.c index eaa35da..268163b 100644 --- a/image.c +++ b/image.c @@ -602,7 +602,7 @@ void img_render(img_t *img) sx = 0; sw = img->w; dx = img->x; - dw = img->w * img->zoom; + dw = MAX(img->w * img->zoom, 1); } if (img->y <= 0) { sy = -img->y / img->zoom + 0.5; @@ -613,7 +613,7 @@ void img_render(img_t *img) sy = 0; sh = img->h; dy = img->y; - dh = img->h * img->zoom; + dh = MAX(img->h * img->zoom, 1); } win_clear(win); -- cgit v1.2.3-54-g00ecf