Repository navigation
buildingplan: fix Unlink all skipping mechanisms when freeing - #5916
Merged
Merged
Conversation
Freeing a mechanism removes it from contained_items, which shifts the indices of all entries after it. "Unlink all" iterated the precomputed index list, so after the first freed mechanism the remaining indices pointed at the wrong items: links were skipped or the loop walked off the end of the vector and errored, leaving mechanisms still linked until the option was used again. Snapshot the linked items before mutating instead of iterating the index list directly. Fixes DFHack#5776
SilasD
approved these changes
Sep 16, 2026
SilasD
left a comment
Contributor
There was a problem hiding this comment.
this looks fine. collecting then consuming is a correct pattern since self.links is direct indexes into building.contained_items and we don't necessarily know what order self.links is in.
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.
Summary
buildingplan's "Unlink all" mechanism option only unlinking some links per click (issue Bug:buildingplan.unlink_mechanismsrequiring multiple presses to unlink all #5776).contained_itemsvector, shifting the indices of everything after it. "Unlink all" iterated the precomputed index list, so after the first freed mechanism the remaining indices pointed at the wrong items: links were skipped, or the loop walked off the end of the vector and errored out.Testing
index out of boundsafter the first unlink and left a link behind. With the fix all three links are removed in one pass.contained_itemsmutation) and "Free local and target" modes, plus the "Free all" overlay, all behaving correctly.Fixes #5776