Skip to content

bugfix(gui): Fix preferred starting cash not showing in combo box#2585

Closed
afc-afc0 wants to merge 1 commit intoTheSuperHackers:mainfrom
afc-afc0:bugfix/starting-cash-combo-box
Closed

bugfix(gui): Fix preferred starting cash not showing in combo box#2585
afc-afc0 wants to merge 1 commit intoTheSuperHackers:mainfrom
afc-afc0:bugfix/starting-cash-combo-box

Conversation

@afc-afc0
Copy link
Copy Markdown

Re-populate the starting cash combo box after applying user preferences from INI files in Skirmish, LAN and WOL game setup menus. Previously, the combo box was populated before preferences were applied, so non-standard starting cash values would not appear in the dropdown.

Also fix undefined behavior in PopulateStartingCashComboBox where a past-the-end iterator was dereferenced when the starting cash value was not found in the standard list.

* Fixes #2583

Re-populate the starting cash combo box after applying user preferences
from INI files in Skirmish, LAN and WOL game setup menus. Previously,
the combo box was populated before preferences were applied, so
non-standard starting cash values would not appear in the dropdown.

Also fix undefined behavior in PopulateStartingCashComboBox where a
past-the-end iterator was dereferenced when the starting cash value was
not found in the standard list.
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 12, 2026

Greptile Summary

This PR fixes two related bugs with the starting cash combo box in Skirmish, LAN, and WOL game setup menus. The combo boxes were initially populated before user preferences were applied, causing non-standard cash values to be missing from the dropdown; the fix re-populates them after setStartingCash is called. A second fix corrects undefined behavior in PopulateStartingCashComboBox where the past-the-end iterator it was dereferenced after the search loop, replaced correctly with myGame->getStartingCash().countMoney().

Confidence Score: 5/5

This PR is safe to merge — both fixes are correct and minimal in scope.

The iterator UB fix is semantically correct (myGame->getStartingCash() is exactly what the loop was searching for). The re-populate calls are safe because PopulateStartingCashComboBox always resets before re-adding entries, so double-calling it is idempotent. No new P0/P1 issues were introduced.

No files require special attention.

Important Files Changed

Filename Overview
GeneralsMD/Code/GameNetwork/GUIUtil.cpp Fixes UB in PopulateStartingCashComboBox: replaces past-the-end iterator dereference (it->countMoney()) with myGame->getStartingCash().countMoney(), which is semantically identical and safe.
GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp Adds second PopulateStartingCashComboBox call after setStartingCash from prefs, ensuring the custom cash value is reflected in the UI.
GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp Adds second PopulateStartingCashComboBox call after setStartingCash from prefs, mirroring the Skirmish fix.
GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp Adds second PopulateStartingCashComboBox call after setStartingCash (accounting for the isUsingStats conditional), completing the fix across all three multiplayer menus.

Sequence Diagram

sequenceDiagram
    participant Init as *MenuInit()
    participant Combo as ComboBox (UI)
    participant Prefs as UserPreferences
    participant Util as PopulateStartingCashComboBox

    Init->>Combo: Attach comboBoxStartingCash
    Init->>Util: PopulateStartingCashComboBox(combo, game) [default cash, before prefs]
    Init->>Prefs: pref.getStartingCash()
    Init->>Init: game->setStartingCash(prefCash)
    Note over Init,Util: FIX: re-populate after applying prefs
    Init->>Util: PopulateStartingCashComboBox(combo, game) [preferred cash, correct selection]
    Util->>Combo: GadgetComboBoxReset
    Util->>Combo: Add standard entries
    alt cash not in standard list (UB fix)
        Util->>Combo: Add custom entry using myGame->getStartingCash().countMoney()
    end
    Util->>Combo: GadgetComboBoxSetSelectedPos
Loading

Reviews (1): Last reviewed commit: "bugfix(gui): Fix preferred starting cash..." | Re-trigger Greptile

@afc-afc0 afc-afc0 closed this Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preferred starting cash from user INI file doesn't show in combo box

1 participant