Warn about loading dead bodies, but handle safely. #5167
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.
Save games could fail to load due to the body index being written as
(Uint32)-1
.Handle getting an out-of-range / SDL_MAX_UINT32 value when trying to find a body by returning
nullptr
instead.This allows savegames to load despite this issue.
The issue itself is caused by the
AICmdFlyAround
having a pointer to aBody *m_obstructor
that it does not own and is not refcounted. This can be destroyed before/whilst saving, which fails to find the body ('cos it's gone), the GetIndexForBody returns(Uint32)-1
, and upon loading it crashes.I would like to have fixed the actual cause by this COVID19 vaccination has hit me like a bus and I feel like I've got flu.
So posting this as-is for possible merging, comments, and suggestions. Either other can fix it, or it can wait until my brain works again.