fix: segfault during crafting setup #40233
Merged
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
SUMMARY: Bugfixes "Fixes a segfault during initializing crafts"
Purpose of change
Crafting would sometimes crash while building a list of possible liquid components for the player to chose among. Like #40227, this was related to a naive use of
legacy_front
that assumed the compared items would have contents and that those contents would have charges.Describe the solution
Replaced
legacy_front
call withonly_item
initem_ptr_compare_by_charges
.Describe alternatives you've considered
Use
get_item_with
and filter for a contained item with charges; I couldn't get this to work in context, due to differing const expectations.Testing
Tested using a known-bad save file from an issue report.
Additional context
The affected comparator function seems to only be used in one place. Not sure if the assumption that we're dealing with a list of liquid containers would be valid if used elsewhere; if not, this will probably cause debug messages and possible UB.
Might fix #40149 : i tested against his save file and was able to reproduce a segfault when crafting ethanol, which no longer happened after patch was applied.