Fix T101185: New Mikktspace crashes on meshes without valid triangles

The code already had a check for meshes with zero triangles, but it
didn't catch the case where all triangles are flagged as degenerate.
A simple way to reproduce this is to take a mesh and scale it to zero.

After checking the code, it turns out that in this case it's supposed
to just set all tangents to zero, so the fix simply is to detect this
case and skip the computation.
This commit is contained in:
Lukas Stockner 2022-10-05 02:42:43 +02:00
parent f9a10e7ed0
commit b804f925c7
Notes: blender-bot 2023-02-14 07:45:38 +01:00
Referenced by issue #101185, Regression: Certain mesh cause crash on render
1 changed files with 20 additions and 14 deletions

View File

@ -178,24 +178,30 @@ template<typename Mesh> class Mikktspace {
// put the degenerate triangles last.
degenPrologue();
// evaluate triangle level attributes and neighbor list
initTriangle();
if (nrTriangles == 0) {
// No point in building tangents if there are no non-degenerate triangles, so just zero them
tSpaces.resize(nrTSpaces);
}
else {
// evaluate triangle level attributes and neighbor list
initTriangle();
// match up edge pairs
buildNeighbors();
// match up edge pairs
buildNeighbors();
// based on the 4 rules, identify groups based on connectivity
build4RuleGroups();
// based on the 4 rules, identify groups based on connectivity
build4RuleGroups();
// make tspaces, each group is split up into subgroups.
// Finally a tangent space is made for every resulting subgroup
generateTSpaces();
// make tspaces, each group is split up into subgroups.
// Finally a tangent space is made for every resulting subgroup
generateTSpaces();
// degenerate quads with one good triangle will be fixed by copying a space from
// the good triangle to the coinciding vertex.
// all other degenerate triangles will just copy a space from any good triangle
// with the same welded index in vertices[].
degenEpilogue();
// degenerate quads with one good triangle will be fixed by copying a space from
// the good triangle to the coinciding vertex.
// all other degenerate triangles will just copy a space from any good triangle
// with the same welded index in vertices[].
degenEpilogue();
}
uint index = 0;
for (uint f = 0; f < nrFaces; f++) {