diff --git a/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp index ab56b662681..11dbafa3092 100644 --- a/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp +++ b/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp @@ -135,6 +135,7 @@ static Bool buttonPushed = false; static const char *nextScreen = NULL; static Bool raiseMessageBoxes = false; static Bool launchGameNext = FALSE; +static Bool isHandlingDisconnect = false; // window ids ------------------------------------------------------------------------------ static NameKeyType parentWOLGameSetupID = NAMEKEY_INVALID; @@ -1164,6 +1165,13 @@ Bool initialAcceptEnable = FALSE; //------------------------------------------------------------------------------------------------- void WOLGameSetupMenuInit( WindowLayout *layout, void *userData ) { + // Prevent infinite recursion if we're already handling a disconnect + if (isHandlingDisconnect) + { + DEBUG_LOG(("WOLGameSetupMenuInit() - already handling disconnect, returning to prevent recursion")); + return; + } + if (TheGameSpyGame && TheGameSpyGame->isGameInProgress()) { TheGameSpyGame->setGameInProgress(FALSE); @@ -1181,6 +1189,7 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData ) GSMessageBoxOk( title, body ); TheGameSpyInfo->reset(); DEBUG_LOG(("WOLGameSetupMenuInit() - game was in progress, and we were disconnected, so pop immediate back to main menu")); + isHandlingDisconnect = true; TheShell->popImmediate(); return; } @@ -1188,6 +1197,7 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData ) // If we init while the game is in progress, we are really returning to the menu // after the game. So, we pop the menu and go back to the lobby. Whee! DEBUG_LOG(("WOLGameSetupMenuInit() - game was in progress, so pop immediate back to lobby")); + isHandlingDisconnect = true; TheShell->popImmediate(); if (TheGameSpyPeerMessageQueue && TheGameSpyPeerMessageQueue->isConnected()) { @@ -1363,6 +1373,9 @@ static void shutdownComplete( WindowLayout *layout ) //------------------------------------------------------------------------------------------------- void WOLGameSetupMenuShutdown( WindowLayout *layout, void *userData ) { + // Reset the disconnect handling flag to allow the menu to reinitialize properly + isHandlingDisconnect = false; + TheGameSpyInfo->unregisterTextWindow(listboxGameSetupChat); if( WOLMapSelectLayout ) diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp index 4943572fa85..4121c45da92 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp @@ -146,6 +146,7 @@ static Bool buttonPushed = false; static const char *nextScreen = NULL; static Bool raiseMessageBoxes = false; static Bool launchGameNext = FALSE; +static Bool isHandlingDisconnect = false; // window ids ------------------------------------------------------------------------------ static NameKeyType parentWOLGameSetupID = NAMEKEY_INVALID; @@ -1695,6 +1696,13 @@ Bool initialAcceptEnable = FALSE; //------------------------------------------------------------------------------------------------- void WOLGameSetupMenuInit( WindowLayout *layout, void *userData ) { + // Prevent infinite recursion if we're already handling a disconnect + if (isHandlingDisconnect) + { + DEBUG_LOG(("WOLGameSetupMenuInit() - already handling disconnect, returning to prevent recursion")); + return; + } + NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); if (pLobbyInterface == nullptr) { @@ -1879,6 +1887,7 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData ) GSMessageBoxOk( title, body ); TheGameSpyInfo->reset(); DEBUG_LOG(("WOLGameSetupMenuInit() - game was in progress, and we were disconnected, so pop immediate back to main menu")); + isHandlingDisconnect = true; TheShell->popImmediate(); return; } @@ -1887,6 +1896,7 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData ) // If we init while the game is in progress, we are really returning to the menu // after the game. So, we pop the menu and go back to the lobby. Whee! DEBUG_LOG(("WOLGameSetupMenuInit() - game was in progress, so pop immediate back to lobby")); + isHandlingDisconnect = true; TheShell->popImmediate(); // TODO_NGMP: Only do this if still connected to service @@ -2163,6 +2173,9 @@ static void shutdownComplete( WindowLayout *layout ) //------------------------------------------------------------------------------------------------- void WOLGameSetupMenuShutdown( WindowLayout *layout, void *userData ) { + // Reset the disconnect handling flag to allow the menu to reinitialize properly + isHandlingDisconnect = false; + NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); if (pLobbyInterface != nullptr)