From 6c8aff01c6a98a9d16cb59a70ce6f5c90a4de6e5 Mon Sep 17 00:00:00 2001 From: Dominic Nancekievill Date: Mon, 15 Nov 2021 08:02:05 +0000 Subject: [PATCH] Fix bug where rasterize() hangs on Apple silicon If any edges of the triangle are horizontal or vertical, it's possible for the raXX variables, and thus d, to get a division by zero leading to +Inf. On Intel, when +Inf is converted to int and back with d = float64(int(d)) the result is a very large negative number which the existing check converted to zero. On ARM (or at least on Apple Silicon which is where I ran into the problem) the result is a very large positive number, causing the function to hang. --- context.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/context.go b/context.go index 38467dd..7098e52 100644 --- a/context.go +++ b/context.go @@ -195,6 +195,9 @@ func (dc *Context) rasterize(v0, v1, v2 Vertex, s0, s1, s2 Vector) RasterizeInfo if w02 < 0 && d2 > d { d = d2 } + if d == math.Inf(1) { + d = 0 + } d = float64(int(d)) if d < 0 { // occurs in pathological cases