fix: force a complete QBVH rebuild when it gets too imbalanced. #185
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.
In many situations (see linked issues), especially at the first simulation frame, but also if many objects are inserted at once during the simulation, the QBVH incremental update algorithm could lead to a degenerate tree. Ideally the fix would improve the incremental update to lower risks of imbalance, but this is a very difficult problem.
A way simpler, but less efficient, fix (that is implemented in this PR) is to force a complete tree rebuild if it reaches a certain depth, indicating degeneracy. That depth is set to 15, which for a perfectly balanced QBVH, can hold
4^15 = 1.073.741.824
leaves (meaning that past that number of object in the tree you are guaranteed to trigger a forced rebuild at every update. But this is a very unlikely number to reach in practical games).Fix #146
Close #169
Fix dimforge/rapier#466
Fix dimforge/rapier#532
Fix dimforge/rapier#558
Fix dimforge/rapier#450