[Bf-blender-cvs] [b804f925c70] master: Fix T101185: New Mikktspace crashes on meshes without valid triangles

Lukas Stockner noreply at git.blender.org
Wed Oct 5 03:06:45 CEST 2022


Commit: b804f925c70cb7245038c14bede3ede11aed9a37
Author: Lukas Stockner
Date:   Wed Oct 5 02:42:43 2022 +0200
Branches: master
https://developer.blender.org/rBb804f925c70cb7245038c14bede3ede11aed9a37

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.

===================================================================

M	intern/mikktspace/mikktspace.hh

===================================================================

diff --git a/intern/mikktspace/mikktspace.hh b/intern/mikktspace/mikktspace.hh
index 2e5b0b065a8..e2c7084566f 100644
--- a/intern/mikktspace/mikktspace.hh
+++ b/intern/mikktspace/mikktspace.hh
@@ -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++) {



More information about the Bf-blender-cvs mailing list