Fix crash in _map_age_dead_critters #258
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.
This PR fixes crashing in
_map_age_dead_critters
function because the same object destroyed twice.I have a save file on Fallout Of Nevada where it happens. Probably reproduceable via keeping corpse on the lowest-index tile and waiting for a while.
It was caused by
objectFindFirst
/objectFindNext
functions which returned the same object twice due to off-by-one error ingObjectFindTile
variable.After calling
objectFindFirst()
functiongObjectFindTile
variable holds index of tile where object was found. After few calls toobjectFindNext
when this tile is exhausted we do postfix increment ongObjectFindTile
so we start to fetch objects from the same tile. When tile is exhausted second time then we jump to the next tile becausegObjectFindTile
already incremented in the first exhausting.So, for this function we consider
gObjectFindTile
as a "tile where to lookup when current list ends". It should always be next tile.Of course it is possible to keep
gObjectFindTile
meaning as "tile where we currently iterating" but this will lead to more changes inobjectFindNext
function, not just changing postfix increment into prefix but also checkinggObjectFindTile
is still in the range.This PR affects
objectFindFirst
/objectFindNext
andobjectFindFirstAtElevation
/objectFindNextAtElevation
functions. Other functionobjectFindFirstAtLocation
setsgObjectFindTile
variable butobjectFindNextAtLocation
is not using it.