Fixes crash during save due to invalid ammo_location #50525
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 crash due to invalid ammo_location"
Purpose of change
Fixes #50399
The problem was that due to trying to reload a bow a container with appropriate ammunition was set as an ammo_location for the bow. However if that container was later dropped the game would crash during save due to the ammo_location no longer being valid.
Describe the solution
ammo_location is only saved if it is valid.
Describe alternatives you've considered
Preventing longbows from ever being reloadable. However this would not fix existing saves that already have an ammo_location set (and worse outside from manually removing the ammo_location from the save there would no longer be a way to fix it by "reloading" the bow and setting a new ammo_location.
In addition this problem might not be restricted to bows. If ANY ammo_location becomes invalid for whatever reason and the player does not reload between that moment and the next save the game would crash.
Testing
Load the save referenced in #50399 and dropped the double rifle case and saved. The game no longer crashed.
For debug testing: