Skip to content

Commit 0d713f2

Browse files
authored
[GEN][ZH] Prevent crashing from evaluating and saving disabled options in the Options Menu (#1028)
1 parent db0730f commit 0d713f2

File tree

2 files changed

+106
-78
lines changed
  • GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus
  • Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus

2 files changed

+106
-78
lines changed

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -923,11 +923,14 @@ static void saveOptions( void )
923923

924924
//-------------------------------------------------------------------------------------------------
925925
// send Delay
926-
TheWritableGlobalData->m_firewallSendDelay = GadgetCheckBoxIsChecked(checkSendDelay);
927-
if (TheGlobalData->m_firewallSendDelay) {
928-
(*pref)["SendDelay"] = AsciiString("yes");
929-
} else {
930-
(*pref)["SendDelay"] = AsciiString("no");
926+
if (checkSendDelay && checkSendDelay->winGetEnabled())
927+
{
928+
TheWritableGlobalData->m_firewallSendDelay = GadgetCheckBoxIsChecked(checkSendDelay);
929+
if (TheGlobalData->m_firewallSendDelay) {
930+
(*pref)["SendDelay"] = AsciiString("yes");
931+
} else {
932+
(*pref)["SendDelay"] = AsciiString("no");
933+
}
931934
}
932935

933936
//-------------------------------------------------------------------------------------------------
@@ -1000,29 +1003,33 @@ static void saveOptions( void )
10001003

10011004
//-------------------------------------------------------------------------------------------------
10021005
// LOD
1003-
Bool levelChanged=FALSE;
1004-
GadgetComboBoxGetSelectedPos( comboBoxDetail, &index );
1005-
//The levels stored by the LOD Manager are inverted compared to GUI so find correct one:
1006-
switch (index) {
1007-
case HIGHDETAIL:
1008-
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_HIGH);
1009-
break;
1010-
case MEDIUMDETAIL:
1011-
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_MEDIUM);
1012-
break;
1013-
case LOWDETAIL:
1014-
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_LOW);
1015-
break;
1016-
case CUSTOMDETAIL:
1017-
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_CUSTOM);
1018-
break;
1019-
default:
1020-
DEBUG_ASSERTCRASH(FALSE,("LOD passed in was %d, %d is not a supported LOD",index,index));
1021-
break;
1022-
}
1006+
if (comboBoxDetail && comboBoxDetail->winGetEnabled())
1007+
{
1008+
Bool levelChanged=FALSE;
1009+
GadgetComboBoxGetSelectedPos( comboBoxDetail, &index );
10231010

1024-
if (levelChanged)
1025-
(*pref)["StaticGameLOD"] = TheGameLODManager->getStaticGameLODLevelName(TheGameLODManager->getStaticLODLevel());
1011+
//The levels stored by the LOD Manager are inverted compared to GUI so find correct one:
1012+
switch (index) {
1013+
case HIGHDETAIL:
1014+
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_HIGH);
1015+
break;
1016+
case MEDIUMDETAIL:
1017+
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_MEDIUM);
1018+
break;
1019+
case LOWDETAIL:
1020+
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_LOW);
1021+
break;
1022+
case CUSTOMDETAIL:
1023+
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_CUSTOM);
1024+
break;
1025+
default:
1026+
DEBUG_ASSERTCRASH(FALSE,("LOD passed in was %d, %d is not a supported LOD",index,index));
1027+
break;
1028+
}
1029+
1030+
if (levelChanged)
1031+
(*pref)["StaticGameLOD"] = TheGameLODManager->getStaticGameLODLevelName(TheGameLODManager->getStaticLODLevel());
1032+
}
10261033

10271034
//-------------------------------------------------------------------------------------------------
10281035
// Resolution
@@ -1034,12 +1041,11 @@ static void saveOptions( void )
10341041
oldDispSettings.bitDepth = TheDisplay->getBitDepth();
10351042
oldDispSettings.windowed = TheDisplay->getWindowed();
10361043

1037-
if (index < TheDisplay->getDisplayModeCount() && index >= 0)
1044+
if (comboBoxResolution && comboBoxResolution->winGetEnabled() && index < TheDisplay->getDisplayModeCount() && index >= 0)
10381045
{
10391046
TheDisplay->getDisplayModeDescription(index,&xres,&yres,&bitDepth);
10401047
if (TheGlobalData->m_xResolution != xres || TheGlobalData->m_yResolution != yres)
10411048
{
1042-
10431049
if (TheDisplay->setDisplayMode(xres,yres,bitDepth,TheDisplay->getWindowed()))
10441050
{
10451051
dispChanged = TRUE;
@@ -1077,19 +1083,27 @@ static void saveOptions( void )
10771083

10781084
//-------------------------------------------------------------------------------------------------
10791085
// IP address
1080-
UnsignedInt ip;
1081-
GadgetComboBoxGetSelectedPos(comboBoxLANIP, &index);
1082-
if (index>=0 && TheGlobalData)
1086+
if (comboBoxLANIP && comboBoxLANIP->winGetEnabled())
10831087
{
1084-
ip = (UnsignedInt)GadgetComboBoxGetItemData(comboBoxLANIP, index);
1085-
TheWritableGlobalData->m_defaultIP = ip;
1086-
pref->setLANIPAddress(ip);
1088+
UnsignedInt ip;
1089+
GadgetComboBoxGetSelectedPos(comboBoxLANIP, &index);
1090+
if (index>=0 && TheGlobalData)
1091+
{
1092+
ip = (UnsignedInt)GadgetComboBoxGetItemData(comboBoxLANIP, index);
1093+
TheWritableGlobalData->m_defaultIP = ip;
1094+
pref->setLANIPAddress(ip);
1095+
}
10871096
}
1088-
GadgetComboBoxGetSelectedPos(comboBoxOnlineIP, &index);
1089-
if (index>=0)
1097+
1098+
if (comboBoxOnlineIP && comboBoxOnlineIP->winGetEnabled())
10901099
{
1091-
ip = (UnsignedInt)GadgetComboBoxGetItemData(comboBoxOnlineIP, index);
1092-
pref->setOnlineIPAddress(ip);
1100+
UnsignedInt ip;
1101+
GadgetComboBoxGetSelectedPos(comboBoxOnlineIP, &index);
1102+
if (index>=0)
1103+
{
1104+
ip = (UnsignedInt)GadgetComboBoxGetItemData(comboBoxOnlineIP, index);
1105+
pref->setOnlineIPAddress(ip);
1106+
}
10931107
}
10941108

10951109
//-------------------------------------------------------------------------------------------------

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -974,11 +974,14 @@ static void saveOptions( void )
974974

975975
//-------------------------------------------------------------------------------------------------
976976
// send Delay
977-
TheWritableGlobalData->m_firewallSendDelay = GadgetCheckBoxIsChecked(checkSendDelay);
978-
if (TheGlobalData->m_firewallSendDelay) {
979-
(*pref)["SendDelay"] = AsciiString("yes");
980-
} else {
981-
(*pref)["SendDelay"] = AsciiString("no");
977+
if (checkSendDelay && checkSendDelay->winGetEnabled())
978+
{
979+
TheWritableGlobalData->m_firewallSendDelay = GadgetCheckBoxIsChecked(checkSendDelay);
980+
if (TheGlobalData->m_firewallSendDelay) {
981+
(*pref)["SendDelay"] = AsciiString("yes");
982+
} else {
983+
(*pref)["SendDelay"] = AsciiString("no");
984+
}
982985
}
983986

984987
//-------------------------------------------------------------------------------------------------
@@ -1054,29 +1057,33 @@ static void saveOptions( void )
10541057

10551058
//-------------------------------------------------------------------------------------------------
10561059
// LOD
1057-
Bool levelChanged=FALSE;
1058-
GadgetComboBoxGetSelectedPos( comboBoxDetail, &index );
1059-
//The levels stored by the LOD Manager are inverted compared to GUI so find correct one:
1060-
switch (index) {
1061-
case HIGHDETAIL:
1062-
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_HIGH);
1063-
break;
1064-
case MEDIUMDETAIL:
1065-
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_MEDIUM);
1066-
break;
1067-
case LOWDETAIL:
1068-
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_LOW);
1069-
break;
1070-
case CUSTOMDETAIL:
1071-
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_CUSTOM);
1072-
break;
1073-
default:
1074-
DEBUG_ASSERTCRASH(FALSE,("LOD passed in was %d, %d is not a supported LOD",index,index));
1075-
break;
1076-
}
1060+
if (comboBoxDetail && comboBoxDetail->winGetEnabled())
1061+
{
1062+
Bool levelChanged=FALSE;
1063+
GadgetComboBoxGetSelectedPos( comboBoxDetail, &index );
10771064

1078-
if (levelChanged)
1079-
(*pref)["StaticGameLOD"] = TheGameLODManager->getStaticGameLODLevelName(TheGameLODManager->getStaticLODLevel());
1065+
//The levels stored by the LOD Manager are inverted compared to GUI so find correct one:
1066+
switch (index) {
1067+
case HIGHDETAIL:
1068+
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_HIGH);
1069+
break;
1070+
case MEDIUMDETAIL:
1071+
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_MEDIUM);
1072+
break;
1073+
case LOWDETAIL:
1074+
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_LOW);
1075+
break;
1076+
case CUSTOMDETAIL:
1077+
levelChanged=TheGameLODManager->setStaticLODLevel(STATIC_GAME_LOD_CUSTOM);
1078+
break;
1079+
default:
1080+
DEBUG_ASSERTCRASH(FALSE,("LOD passed in was %d, %d is not a supported LOD",index,index));
1081+
break;
1082+
}
1083+
1084+
if (levelChanged)
1085+
(*pref)["StaticGameLOD"] = TheGameLODManager->getStaticGameLODLevelName(TheGameLODManager->getStaticLODLevel());
1086+
}
10801087

10811088
//-------------------------------------------------------------------------------------------------
10821089
// Resolution
@@ -1088,12 +1095,11 @@ static void saveOptions( void )
10881095
oldDispSettings.bitDepth = TheDisplay->getBitDepth();
10891096
oldDispSettings.windowed = TheDisplay->getWindowed();
10901097

1091-
if (index < TheDisplay->getDisplayModeCount() && index >= 0)
1098+
if (comboBoxResolution && comboBoxResolution->winGetEnabled() && index < TheDisplay->getDisplayModeCount() && index >= 0)
10921099
{
10931100
TheDisplay->getDisplayModeDescription(index,&xres,&yres,&bitDepth);
10941101
if (TheGlobalData->m_xResolution != xres || TheGlobalData->m_yResolution != yres)
10951102
{
1096-
10971103
if (TheDisplay->setDisplayMode(xres,yres,bitDepth,TheDisplay->getWindowed()))
10981104
{
10991105
dispChanged = TRUE;
@@ -1131,19 +1137,27 @@ static void saveOptions( void )
11311137

11321138
//-------------------------------------------------------------------------------------------------
11331139
// IP address
1134-
UnsignedInt ip;
1135-
GadgetComboBoxGetSelectedPos(comboBoxLANIP, &index);
1136-
if (index>=0 && TheGlobalData)
1140+
if (comboBoxLANIP && comboBoxLANIP->winGetEnabled())
11371141
{
1138-
ip = (UnsignedInt)GadgetComboBoxGetItemData(comboBoxLANIP, index);
1139-
TheWritableGlobalData->m_defaultIP = ip;
1140-
pref->setLANIPAddress(ip);
1142+
UnsignedInt ip;
1143+
GadgetComboBoxGetSelectedPos(comboBoxLANIP, &index);
1144+
if (index>=0 && TheGlobalData)
1145+
{
1146+
ip = (UnsignedInt)GadgetComboBoxGetItemData(comboBoxLANIP, index);
1147+
TheWritableGlobalData->m_defaultIP = ip;
1148+
pref->setLANIPAddress(ip);
1149+
}
11411150
}
1142-
GadgetComboBoxGetSelectedPos(comboBoxOnlineIP, &index);
1143-
if (index>=0)
1151+
1152+
if (comboBoxOnlineIP && comboBoxOnlineIP->winGetEnabled())
11441153
{
1145-
ip = (UnsignedInt)GadgetComboBoxGetItemData(comboBoxOnlineIP, index);
1146-
pref->setOnlineIPAddress(ip);
1154+
UnsignedInt ip;
1155+
GadgetComboBoxGetSelectedPos(comboBoxOnlineIP, &index);
1156+
if (index>=0)
1157+
{
1158+
ip = (UnsignedInt)GadgetComboBoxGetItemData(comboBoxOnlineIP, index);
1159+
pref->setOnlineIPAddress(ip);
1160+
}
11471161
}
11481162

11491163
//-------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)