Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where rasterize() hangs on Apple silicon #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

djn24
Copy link

@djn24 djn24 commented Nov 18, 2021

Hi,

Thanks for writing fauxgl, I've found it very useful. I ran into a problem when running my project on an Apple silicon laptop. Please consider this patch which fixes the problem.

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
converts 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.

You can verify this with the following small fragment of code:
var one float64 = 1
var zero float64 = 0
var divZero float64 = one / zero
var castAndCastBack = float64(int(divZero))
fmt.Printf("%f\n", castAndCastBack)
On an Intel CPU that will print a very large negative number, on Apple silicon a very large positive number.

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.
@TheFranconianCoder
Copy link

@djn24 Thanks for this one. Switched from Windows 10 to an Apple Silicon MacOS and my code ran for some models infinite. Would be great to see this merged. @fogleman

@EduardoOliveira
Copy link

I think I'm facing the same issue in raspberry pies...
Some models render ok, others just don't finish...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants