Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes crash during save due to invalid ammo_location #50525

Merged
merged 1 commit into from
Aug 7, 2021

Conversation

satheon49
Copy link
Contributor

@satheon49 satheon49 commented Aug 6, 2021

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:

  1. Spawn bow, 2 arrows and quiver
  2. Wear quiver, wield bow
  3. Pick up 1 arrow into the quiver
  4. "Reload bow"-> pick quiver as source
  5. Drop quiver
  6. Save

@actual-nh actual-nh added <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Items: Ammo / Guns Ammunition for all kinds of weapons and these weapons themselves Items: Containers Things that hold other things labels Aug 6, 2021
@actual-nh actual-nh requested a review from ifreund August 6, 2021 13:34
@mqrause
Copy link
Contributor

mqrause commented Aug 6, 2021

This sounds like it possibly also fixes #50029.

@satheon49
Copy link
Contributor Author

Very likely. The crash for 50399 was caused by a call of item_location::calc_index too (with item_location being the ammo_location which was null at that point)

@Qrox
Copy link
Contributor

Qrox commented Aug 6, 2021

Does this fix #39930?

@satheon49
Copy link
Contributor Author

satheon49 commented Aug 6, 2021

I could not reproduce a crash with smashing the vehicle (with or without PR) but saving with an unloaded vehicle is fixed by this PR too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Items: Ammo / Guns Ammunition for all kinds of weapons and these weapons themselves Items: Containers Things that hold other things
Projects
None yet
Development

Successfully merging this pull request may close these issues.

autosave exits game
5 participants