Skip to content

Commit 0e5e016

Browse files
committed
clusterizer: Fix meshlet construction for an empty index set
An empty submesh should result in 0 generated clusters; this was previously asserting in kdtreeBuild - the assertion was benign but it seems better to support this via an early out.
1 parent 12358ad commit 0e5e016

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

demo/tests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,17 @@ static void clusterBoundsDegenerate()
10591059
assert(bounds2.center[2] - bounds2.radius <= 0 && bounds2.center[2] + bounds2.radius >= 1);
10601060
}
10611061

1062+
static void meshletsEmpty()
1063+
{
1064+
const float vbd[4 * 3] = {};
1065+
1066+
meshopt_Meshlet ml[1];
1067+
unsigned int mv[4];
1068+
unsigned char mt[8];
1069+
size_t mc = meshopt_buildMeshlets(ml, mv, mt, NULL, 0, vbd, 4, sizeof(float) * 3, 64, 64, 0.f);
1070+
assert(mc == 0);
1071+
}
1072+
10621073
static void meshletsDense()
10631074
{
10641075
const float vbd[4 * 3] = {};
@@ -2187,6 +2198,7 @@ void runTests()
21872198

21882199
clusterBoundsDegenerate();
21892200

2201+
meshletsEmpty();
21902202
meshletsDense();
21912203
meshletsSparse();
21922204

src/clusterizer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,9 @@ size_t meshopt_buildMeshlets(meshopt_Meshlet* meshlets, unsigned int* meshlet_ve
615615

616616
assert(cone_weight >= 0 && cone_weight <= 1);
617617

618+
if (index_count == 0)
619+
return 0;
620+
618621
meshopt_Allocator allocator;
619622

620623
TriangleAdjacency2 adjacency = {};

0 commit comments

Comments
 (0)