Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

game.cpp: Fix loading commander droids without psGroup #3596

Merged

Conversation

ManManson
Copy link
Member

@ManManson ManManson commented Jan 11, 2024

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 is nullptr.

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

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` is `nullptr`.

If a player attempts to save the game right after
this transition and then loads the savegame again,
the game will 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.

Signed-off-by: Pavel Solodovnikov <[email protected]>
@KJeff01 KJeff01 added this to the 4.5.0-beta1 milestone Jan 13, 2024
@KJeff01
Copy link
Member

KJeff01 commented Jan 13, 2024

Makes sense. It works from my tests so I'm going to merge it and see if anyone hits an issue, if any.

@KJeff01 KJeff01 merged commit ba37c6e into Warzone2100:master Jan 13, 2024
35 checks passed
@ManManson ManManson deleted the fix_load_save_missing_commander_group branch February 19, 2024 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash when removing droids from group
2 participants