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(gameclient): destroy each drawable once when a match is left

Olcay Seygan5a5ed08c589f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 43f9bf7af..7939315de 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1736,6 +1736,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
log on its own.
- Closing a laptop's lid, or pulling out the drive the game is installed on, ends the game with a box saying its data is gone. The next read from the missing drive used to crash it.
- A custom map that defines its own way for a vehicle to move no longer crashes the game with "Pure virtual function called" when the match ends. The game freed that map's movement rules and then kept reading the freed record. The shipped Hovercraft test map did it every time, and so could any map handed to you in a lobby.
+- Leaving a match from the menu no longer ends in a "Game crash: Pure virtual function called" box. Since v3.1.0 anything that died in the last instant before you left was thrown away twice as the game cleared the battlefield, which in testing was every exit from a running skirmish, and the box closed the game with an error instead of returning you to the menu.
- A missing save folder no longer costs you maps. The game listed the folder it runs from instead, and the tidy-up after a match deleted the .map files it found there.
- Screenshots come out straight at any width. At 1366 wide each row slid sideways, and at any width that does not divide by eight the game read past the end of the picture.
- Quitting the Windows game under Proton, the way a Steam Deck used to run it, no longer crashes on the way out.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp
index 165575036..35bc8eb64 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp
@@ -534,7 +534,7 @@ void GameClient::init( void )
/** Reset the game client for a new game */
void GameClient::reset( void )
{
- Drawable *draw, *nextDraw;
+ Drawable *draw;
// m_drawableHash.clear();
// m_drawableHash.resize(DRAWABLE_HASH_SIZE);
@@ -556,12 +556,18 @@ void GameClient::reset( void )
if (TheSelectionTranslator)
TheSelectionTranslator->forgetPendingSquads();
- // destroy all Drawables
- for( draw = m_drawableList; draw; draw = nextDraw )
+ // destroy all Drawables. The clear-game tick resets from inside the tick, where what the tick
+ // destroyed before it stays on the list until the sync point; destroying one of those again queued
+ // it twice, and the flush below deleted it twice: the "Pure virtual function called" box on
+ // leaving a match.
+ std::vector<Drawable *> listed;
+ for( draw = m_drawableList; draw; draw = draw->getNextDrawable() )
{
- nextDraw = draw->getNextDrawable();
- destroyDrawable( draw );
+ if( std::find( m_destroyedInTick.begin(), m_destroyedInTick.end(), draw ) == m_destroyedInTick.end() )
+ listed.push_back( draw );
}
+ for( size_t i = 0; i < listed.size(); ++i )
+ destroyDrawable( listed[ i ] );
// the clear-game tick resets from inside the tick: what it made before that was never linked
for( size_t i = 0; i < m_madeInTick.size(); ++i )
{