Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(gameengine): skip the score screen's audio update when quitting

Olcay Seygan35c3652c4233
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 149b35bd1..149e3c308 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1297,6 +1297,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- Two blocks of 2003 assembly destroyed registers and took down the main menu.
- A model file with no skeleton in it is refused as it loads. It used to load, and the game went down the first time anything asked it for a bone.
- Quitting faulted twice every time; it now takes about half a second.
+- Quitting the game from the score screen crashed it in 2.4.0. The fix that stopped the score music cleanly also ran the sound once more while the game was closing, by which point the battlefield it places the listener on was already gone. The game closes cleanly from there again, and the score music still stops the moment you leave the screen.
- A long chat message or an unusual map name could kill the process.
- A map name the game cannot make sense of is refused as you start, instead of taking the game down later. A path with a space in it and no quotes around it left the loader walking the same step of that path forever, growing a string until it ran out of room, and the game then went on starting with half of itself missing. What you saw was a crash a second later, in the part of the game that runs a match, naming nothing that had anything to do with it. Any failure during start-up now stops the game there and says which one it was.
- A downloaded map made for another mod loads instead of crashing as the match starts. Maps can carry their own tweaks to units, and one a player tried gave a wall a setting Zero Hour has never had; one unfamiliar line was enough to take the whole game down. A setting the game does not know is now passed over and the rest of the map's tweaks still apply.
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameMain.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameMain.cpp
index aef3d163e..ad3faabf7 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameMain.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameMain.cpp
@@ -43,9 +43,13 @@ void GameMain( int argc, char *argv[] )
// run it
TheGameEngine->execute();
- // since execute() returned, we are exiting the game
- delete TheGameEngine;
+ // since execute() returned, we are exiting the game. The global goes first: teardown can
+ // pump the window procedure (a crash dialog's ShowWindow sends WM_ACTIVATEAPP), and WndProc
+ // would otherwise call into an engine whose subsystems are half gone. Every reader on the
+ // teardown path checks it for NULL.
+ GameEngine *engine = TheGameEngine;
TheGameEngine = NULL;
+ delete engine;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ScoreScreen.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ScoreScreen.cpp
index dc7b08f3e..6cfddc289 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ScoreScreen.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ScoreScreen.cpp
@@ -415,7 +415,11 @@ void ScoreScreenShutdown( WindowLayout *layout, void *userData )
// music held its volume through the whole load and did all two seconds of its fade on top of
// the track the shell map's first script frame starts, so both played at once.
TheAudio->removeAudioEvent( AHSV_StopTheMusic );
- TheAudio->update(); // so the stop lands at the click, before the load rather than after it
+ // So the stop lands at the click, before the load rather than after it. Not on the way out
+ // of the program: quitting with this screen up runs this from the shell's destructor, after
+ // the terrain and the view the listener update reads are already freed.
+ if( TheGameEngine != NULL && !TheGameEngine->getQuitting() )
+ TheAudio->update();
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLQuickMatchMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLQuickMatchMenu.cpp
index f64b004ac..887147655 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLQuickMatchMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLQuickMatchMenu.cpp
@@ -936,7 +936,7 @@ void WOLQuickMatchMenuShutdown( WindowLayout *layout, void *userData )
{
TheGameSpyInfo->unregisterTextWindow(quickmatchTextWindow);
- if (!TheGameEngine->getQuitting())
+ if (TheGameEngine != NULL && !TheGameEngine->getQuitting()) // NULL when the shell's destructor runs this on exit
saveQuickMatchOptions();
parentWOLQuickMatch = NULL;