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: None
Purpose of change
Simplifies
aim_activity_actor
as a follow-up after #40684Fixes #42250
The crash happened due to the following coincidence:
aim_activity_actor::do_turn(...)
method requires an extra call for marking the activity as finished, so in a case when aiming was finished with player having exactly 0 moves left, that extra call was delayed by 1 turn, and soaim_activity_actor::finish(...)
was also delayed by 1 turn.That 1-turn delay was enough for the woodbow to disappear.
But,
finish(...)
method assumed that the weapon checks done back indo_turn(...)
were still relevant, so it simply dereferenced the weapon pointer, which have turned into a null pointer by that time, without validation.Describe the solution
Removed the need for an extra call by inserting
act.moves_left = 0
indo_turn(...)
wherever necessary.Added a nullptr check in
finish(...)
for robustness in the future.Also, noticed that my old implementation used shared pointers instead of (de-)serializable and more convenient
cata::optional
, so changed that.Removed an enum that was basically a leftover from refactoring.
Describe alternatives you've considered
Just slapping a nullptr check, but that's treating symptoms, not the cause.
Testing
Set (via debugger) avatar's moves and the woodbow's timer to expire as described. The game crashed before, but after this fix the bow allows the last shot before disappearing.