From 5b519cea8ee2a9810f27a42acc7874faa7ebbdbc Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Mon, 13 Jan 2025 08:58:12 +0100 Subject: [PATCH] Underflow re-check caused by allowing lines in negative directions --- gpu.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gpu.lua b/gpu.lua index 84b3bad..9b419b6 100644 --- a/gpu.lua +++ b/gpu.lua @@ -421,11 +421,16 @@ local function runcommand(pos, meta, command) local length = 1 + vector.distance(p1, p2) local dir = vector.direction(p1, p2) local point - -- not the most eficient process for horizontal, vertical - -- or 45 degree lines + -- Not the most efficient process for horizontal, vertical + -- or 45 degree lines. for i = 0, length, 0.3 do point = vector.add(p1, vector.multiply(dir, i)) point = vector.floor(point) + -- Underflow check needed so we don't need more complicated code to + -- calculate dir in negative direction. Overflows are already capped + -- by initiation. + if 1 > point.x then point.x = 1 end + if 1 > point.y then point.y = 1 end if command.antialias then buffer[point.y][point.x] = blend( buffer[point.y][point.x], color, "average")