Fix flex contact filtering compaction - #3495
Open
rootkiller6788 wants to merge 1 commit into
Open
Conversation
The farthest-point sampling loop in filterFlexContacts swapped contacts in place while the selection bookkeeping (selected[]/min_dist[]) was still indexed against the pre-swap array. This corrupted the selection (re-selecting already-picked contacts and skipping valid candidates) and, because the swap was skipped for the final selected contact, left a wrong contact in the kept prefix. Collect the selected contacts in a temporary buffer and compact them into the contact prefix only after the selection loop finishes, so the retained prefix is exactly the set selected by farthest-point sampling.
rootkiller6788
marked this pull request as ready for review
August 24, 2026 03:12
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.
Fixes #3297.
filterFlexContactslimits the number of contacts kept per flex collision pair using farthest-point sampling. The selection loop swappedcontacts[best]into the kept prefix while the loop was still running, so theselected[]/min_dist[]bookkeeping (which is indexed by array position) no longer referred to the same logical contacts after the first swap. In practice this can re-select an already-picked contact (and skip a valid one), and because the swap was intentionally skipped for the final selected contact (whennselected == mjMAXCONPAIR - 1), the truncated prefix could contain a different, unselected contact instead.This change keeps the selected contacts in a temporary buffer and compacts them into the contact prefix only after the selection loop finishes, so the first
nselectedcontacts after filtering are exactly the contacts selected by farthest-point sampling.Verification:
engine_collision_driver.ccompiles cleanly (single-filegcc -cagainst the in-repo headers).