forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply extra care with monster dragging code to avoid segfaults
Based upon my interpretation of the stack-trace in CleverRaven#33104, it appears that `monster::store` is trying to use a dragged_foe that's not null, but is no longer valid, either. This may happen if the foe is dead, or any other condition that may cause the dragged critter object to be destroyed. This commit: - Always tracks the `dragged_foe_id` (an integer) rather than `dragged_foe` (a pointer) directly. - Uses `critter_by_id()` to check the validity of the `dragged_foe_id` on the occasions when it needed. This is the same function used by the savegame loading code to restore the dragged foe. - Moves the dragged_foe-finding functionality to its own method for clarity. - Ensures the dragged_foe-finding code clears relevant status effects and members if we're no longer dragging a valid critter. - Moves the nursebot operation code to its own method, also for clarity. Note that I don't have a reproducable way to induce the bug, so I don't have a great test for this. However it's hard to have a segfault if you don't have a stale pointer to deference in the first place. Fixes CleverRaven#33051. Fixes CleverRaven#33141.
- Loading branch information
Showing
4 changed files
with
85 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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