From dbe8171815ea3b51c3ac87dae1996ae0d8f6eb04 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Mon, 16 Dec 2024 14:51:00 +1300 Subject: Fix overflow error in line drawing function Drawing a line with length of 0x4000 or greater was never terminating. --- arm9/source/devices/screen.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'arm9/source/devices/screen.c') diff --git a/arm9/source/devices/screen.c b/arm9/source/devices/screen.c index f1aa7f9..e394b55 100644 --- a/arm9/source/devices/screen.c +++ b/arm9/source/devices/screen.c @@ -244,11 +244,11 @@ void scr_draw_line(ScreenDevice *scr, u16 *layer, u8 draw) { s16 x_end = (s16) scr->px; s16 y_end = (s16) scr->py; - s16 dx = abs(x_end - x); - s16 dy = -abs(y_end - y); + s32 dx = abs(x_end - x); + s32 dy = -abs(y_end - y); s16 sx = x < x_end ? 1 : -1; s16 sy = y < y_end ? 1 : -1; - s16 e1 = dx + dy; + s32 e1 = dx + dy; if (draw & 0x10) { // Draw 1-bit textured line. @@ -260,7 +260,7 @@ void scr_draw_line(ScreenDevice *scr, u16 *layer, u8 draw) { if (scr->sprite.sprite[y%8][x%8]) { draw_pixel(layer, x, y, c1); } else if (opaque) { draw_pixel(layer, x, y, c0); } if (x == x_end && y == y_end) return; - s16 e2 = e1 << 1; + s32 e2 = e1 << 1; if (e2 >= dy) { e1 += dy; x += sx; } if (e2 <= dx) { e1 += dx; y += sy; } } @@ -270,7 +270,7 @@ void scr_draw_line(ScreenDevice *scr, u16 *layer, u8 draw) { while (1) { draw_pixel(layer, x, y, colour); if (x == x_end && y == y_end) return; - s16 e2 = e1 << 1; + s32 e2 = e1 << 1; if (e2 >= dy) { e1 += dy; x += sx; } if (e2 <= dx) { e1 += dx; y += sy; } } -- cgit v1.2.3-70-g09d2