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): move an already modal window to the top, not onto it twice

Olcay Seygancbf9450ab348
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 214d2e22b..3cb60cf8b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -453,6 +453,7 @@ found and fixed — EA's own, not port damage.**
- Selling a building mid-research gave no refund and left the upgrade in limbo.
- On-screen messages now hold for two and a half seconds and fade in one.
- Closing a dialog while another one sits on top of it no longer leaves the game holding a pointer to the window it just freed. Every click, every keypress and the tab order all read that list, so what it caused was a crash with no pattern to it.
+- A dialog asked to open twice closes once. It went on the list of windows that take every click a second time, closing took one copy off, and the other kept eating input for a window nobody could see.
- Ordering a group to use a special power that can kill the units casting it, the GLA rebel ambush over water being the one that does it every time, no longer walks a list of units that the ambush is deleting underneath.
- A replay that never recorded which seat was yours plays instead of crashing before the map loads.
- Alt-tabbing back into the game no longer leaves you in waypoint mode. Alt is the key you hold to lay a route and it is also the key you hold to alt-tab, so the release went to Windows and the game never heard it: every click after that queued another waypoint. Ctrl, shift and the keypad camera keys were the same story.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp
index dac7cc0b5..8babdaf08 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp
@@ -1615,6 +1615,25 @@ Int GameWindowManager::winSetModal( GameWindow *window )
DEBUG_LOG(( "WinSetModal: Non Root window attempted to go modal." ));
return WIN_ERR_INVALID_PARAMETER; // return error if not
}
+
+ // A window already on the stack moves to the top instead of going on twice. winUnsetModal and
+ // windowHiding pop one entry, so a second one stayed behind and went on swallowing input for a
+ // window that had closed.
+ ModalWindow *previous = NULL;
+ for( ModalWindow *existing = m_modalHead; existing != NULL; previous = existing, existing = existing->next )
+ {
+ if( existing->window != window )
+ continue;
+
+ if( previous != NULL )
+ {
+ previous->next = existing->next;
+ existing->next = m_modalHead;
+ m_modalHead = existing;
+ }
+ return WIN_ERR_OK;
+ }
+
// Allocate new Modal Window Entry
modal = newInstance(ModalWindow);
if( modal == NULL )