game.cpp: Fix loading commander droids without psGroup
#3596
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.
When a commander transitions from an offworld mission, it will currently lose its group (actually, this is kind of a bug, too), i.e. its
psGroup
isnullptr
.If a player attempts to save the game right after this transition and then loads the savegame again, the game will likely crash.
loadSaveDroid()
function will try to allocate a new group for these "orphaned" returning commanders.But this new group ID is not in sync with other group IDs that may already be present in the currently processed "droid.json" file and thus may clash with other groups, leading to various memory-related bugs.
For example, this may happen when there is a commander back at the players' base with some commander group assigned.
There is a non-zero probability that the commander which returns from an offworld mission, will try to allocate the same group ID as the commander back at the base.
Fixes: #3592