Skip to content

Conversation

@helmutbuhler
Copy link

@helmutbuhler helmutbuhler commented Jun 3, 2025

Fixes: #995

This fixes a crash when shutting down the GameEngine without calling TheGameEngine->reset() first. This happens during Replay Simulation (see #923).

During normal shutdown in the existing game this cannot happen because shutdown only occurs with the GameMessage::MSG_CLEAR_GAME_DATA message, which calls GameLogic::clearGameData, which in turn calls TheGameEngine->reset()

Why does it crash otherwise?
GameEngine has (among others) two subsystems: TeamFactory and PlayerList, which it initializes in that order. During shutdown (in opposite order) ~TeamFactory() calls ~TeamPrototype(), which calls ~Team(), which calls ThePlayerList->getPlayerCount() (which then will crash because the PlayerList is already destructed).

Resetting first fixes this because it clears all the team prototypes in the TeamFactory.

Changing the order of TeamFactory and PlayerList would probably not work because some other dependency would then likely show up. It also would be a scary change that could break other things. I think resetting first is a valid approach to fix these dependencies and to make sure shutdown always works properly.

@xezon xezon added this to the Stability fixes milestone Jun 3, 2025
@xezon xezon added Bug Something is not working right, typically is user facing Major Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Crash This is a crash, very bad labels Jun 3, 2025
Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Needs to be relicated in Generals.

How often does this crash occur in Replays?

@helmutbuhler
Copy link
Author

How often does this crash occur in Replays?

Happens for every replay.

@xezon
Copy link

xezon commented Jun 4, 2025

Ah ok so this only happens when exiting the game during a match, which cannot happen in the regular client, but only with Debug features.

@xezon xezon added Debug Is mostly debug functionality and removed Bug Something is not working right, typically is user facing labels Jun 4, 2025
@helmutbuhler
Copy link
Author

Can only happen with the new Replay Simulation

@helmutbuhler
Copy link
Author

Updated comment and synced with Generals

@helmutbuhler helmutbuhler changed the title Fix crash in ~GameEngine() without GameLogic::clearGameData() call [GEN][ZH] Fix crash in ~GameEngine() without GameLogic::clearGameData() call Jun 5, 2025
@xezon xezon changed the title [GEN][ZH] Fix crash in ~GameEngine() without GameLogic::clearGameData() call [GEN][ZH] Fix crash on GameEngine shutdown when GameLogic::clearGameData() was not called before Jun 6, 2025
Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@xezon xezon merged commit 0942bed into TheSuperHackers:main Jun 6, 2025
20 checks passed
@xezon xezon deleted the reset_in_dtor_gameengine branch June 6, 2025 12:17
fbraz3 pushed a commit to fbraz3/GeneralsX that referenced this pull request Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Crash This is a crash, very bad Debug Is mostly debug functionality Gen Relates to Generals Major Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Access Violation during cleanup in Replay Simulation

2 participants