Skip to content

Commit 028714e

Browse files
committed
Harden against the case of multiple zero-sized faces at the end of a subd mesh
1 parent 2446385 commit 028714e

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎kernels/common/scene_subdiv_mesh.cpp‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,10 +706,13 @@ namespace embree
706706
{
707707
numHalfEdges = parallel_prefix_sum(faceVertices,faceStartEdge,numFaces(),0,std::plus<unsigned>());
708708

709-
/* Corner case: If the last face has zero edges, start edge index will be invalid.
709+
/* Corner case: If the last faces have zero edges, start edge index will be invalid.
710710
Set it to the last valid half edge index. */
711711
if (numFaces() && faceVertices[numFaces()-1] == 0) {
712-
faceStartEdge[numFaces()-1] = numHalfEdges-1;
712+
/* Walk back through the faces until we find one with non-zero edges */
713+
for (size_t i = numFaces() - 1; i > 0 && faceVertices[i] == 0; i--) {
714+
faceStartEdge[i] = numHalfEdges - 1;
715+
}
713716
}
714717

715718
/* calculate face of each half edge */

0 commit comments

Comments
 (0)