From 0324fefbb9fb018948a8ed9e7afc42e6e3620eb7 Mon Sep 17 00:00:00 2001 From: Tom Janssens Date: Tue, 21 Apr 2020 02:17:10 +0200 Subject: [PATCH] Fix infinite recursive loop in BVH building (#81) 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 --- src/renderer/bvhAccel.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/renderer/bvhAccel.js b/src/renderer/bvhAccel.js index 35c4044..5ffd1ac 100644 --- a/src/renderer/bvhAccel.js +++ b/src/renderer/bvhAccel.js @@ -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