Clamp branching factor#611
Open
stefanatwork wants to merge 6 commits into
Open
Conversation
Clamp BVHBuilderMorton settings to MAX_BRANCHING_FACTOR when an oversized maxBranchingFactor is provided via RTCBuildArguments.\n\nAdd an integration test that exercises rtcBuildBVH with RTC_BUILD_QUALITY_LOW and maxBranchingFactor=64 to verify the Morton build path returns a valid root. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
johguenther
approved these changes
Jul 10, 2026
johguenther
left a comment
Contributor
There was a problem hiding this comment.
LGTM, just some questions/comments
- the regression test does nowhere check whether
childrenare <=8 (MAX_BRANCHING_FACTOR), so basically without the fix, the builder would crash (stack overflow)? But what ifmaxBranchingFactoris set to 9 without the fix / clamp, it may not crash (just slightly above the limit), just be corrupt? - needs un-draft and should be squashed
johguenther
reviewed
Jul 10, 2026
johguenther
requested changes
Jul 10, 2026
johguenther
left a comment
Contributor
There was a problem hiding this comment.
actually, embree_regression_morton_builder_clamp already crashes (without modifications)
johguenther
reviewed
Jul 10, 2026
stefanatwork
marked this pull request as ready for review
July 15, 2026 22:18
johguenther
requested changes
Jul 22, 2026
Contributor
There was a problem hiding this comment.
- test passes, good
- when I remove the fix (clamp branching in builder), the test segfaults (expected, but a fail would be better)
- when I now reduce test requested branching to 6 via
runCase(6), the test still segfaults, bad (segfault is inembree/kernels/common/alloc.h:517allslotMutex[]arenullptr, called bymorton_builder_clamp_regression.cpp:createLeaf()->rtcThreadLocalAlloc())
I'd recommend to replace the asserts by std::throw and remove all other code which allocates or writes to memory. This way the regression test does not depend on asserts being compiled and the thrown exception (in case of a regression) is handled by the test framework (then failing properly instead of crashing -- at least not crashing in the test, but maybe in the builder).
the new file morton_builder_clamp_regression.cpp still needs clang-formated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Limiting the branching factor of the standalone BVH builder.