Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

BVH query: guard the work estimate's shift

islandmede94f725ece62
diff --git a/src/core/BVH.cpp b/src/core/BVH.cpp
index 9ecfac34..f5eb9fe9 100644
--- a/src/core/BVH.cpp
+++ b/src/core/BVH.cpp
@@ -325,7 +325,7 @@ void BVH::queryVertices(const Mesh& mesh, const glm::vec3& center, float radius,
// The set doesn't depend on which thread found what, take() lists it in index order, and the leaves are
// joined in task order.
size_t work = 0; // triangles under the tasks, roughly
- for (uint32_t ni : tasks) work += nodes_[ni].count > 0 ? nodes_[ni].count : mesh.triangleCount() >> depth;
+ for (uint32_t ni : tasks) work += nodes_[ni].count > 0 ? nodes_[ni].count : mesh.triangleCount() >> std::min(depth, 63);
if (work < kSerialTriangles) { // waking threads would cost more
for (uint32_t root : tasks) walk(root, stack_, queryLeaves_, vertBits_);
vertBits_.take(out);