Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Stockner <lukas.stockner@freenet.de>2022-10-05 03:42:43 +0300
committerLukas Stockner <lukas.stockner@freenet.de>2022-10-05 03:42:43 +0300
commitb804f925c70cb7245038c14bede3ede11aed9a37 (patch)
tree2efd5fef5fe09dfa55a1a9d8f5c5f7aa01eea871
parentf9a10e7ed039f5394e1965709104c441c8472c5e (diff)
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.
-rw-r--r--intern/mikktspace/mikktspace.hh34
1 files changed, 20 insertions, 14 deletions
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++) {