Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Fix infinite recursive loop in BVH building (#81)
Browse files Browse the repository at this point in the history
When all primitive centroids are equal during a recursive BVH building step, it results in a recursive loop.
This fix detects this case and returns a leaf node instead.

Co-authored-by: Tom Janssens <tom@corebvba.be>
  • Loading branch information
ToJans and Tom Janssens committed Apr 21, 2020
1 parent e6d951c commit 0324fef
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/renderer/bvhAccel.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ function recursiveBuild(primitiveInfo, start, end) {
}
const dim = maximumExtent(centroidBounds);

if (centroidBounds.max[dim] === centroidBounds.min[dim]) {
return makeLeafNode(primitiveInfo.slice(start, end), bounds);
}

let mid = Math.floor((start + end) / 2);

// middle split method
Expand Down

0 comments on commit 0324fef

Please sign in to comment.