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

Numerical unstable normals calculation causes segfault crashes #130

Open
henkson opened this issue Dec 21, 2023 · 0 comments
Open

Numerical unstable normals calculation causes segfault crashes #130

henkson opened this issue Dec 21, 2023 · 0 comments

Comments

@henkson
Copy link

henkson commented Dec 21, 2023

We encountered a problem where a mesh caused xatlas to crash with a segfault. We were able to strip down the mesh to a very simple example (3 vertices, 2 faces), with this OBJ description:

v 0 695.61237 85.88235
v 0 994.86237 245.88235
v 0 699.2378 87.820755
f 1 2 3
f 2 1 3

The 2 faces share the same vertices but have opposite winding direction. They lie in the YZ plane (x == 0).

We were able to debug the xatlas code and found that the calculation of the normals of the faces goes wrong, because the cross product of two vertices is numerically instable if the angle between them is very small. This is the case for this example, it is a very "long and narrow" triangle.
The calculated normal for both faces is the same (-1, 0, 0), while in fact the first face should have (1, 0, 0).

The code causing the issue is Mesh.computeFaceNormal. It always takes "the first" corner of a face to calculate the normal, while it would be better to use "the corner whose angle is the closest to a right angle".

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

No branches or pull requests

1 participant