Resolved crashes in game options table when changing base ruleset before the mod list was defined

This commit is contained in:
yairm210 2021-11-13 22:18:11 +02:00
parent eefe499fff
commit 4b43ff5b5e

View File

@ -37,6 +37,9 @@ class GameOptionsTable(
top() top()
defaults().pad(5f) defaults().pad(5f)
// We assign this first to make sure addBaseRulesetSelectBox doesn't reference a null object
if (!withoutMods) modCheckboxes = getModCheckboxes()
add(Table().apply { add(Table().apply {
defaults().pad(5f) defaults().pad(5f)
addBaseRulesetSelectBox() addBaseRulesetSelectBox()
@ -59,9 +62,7 @@ class GameOptionsTable(
checkboxTable.addReligionCheckbox(cityStateSlider) checkboxTable.addReligionCheckbox(cityStateSlider)
add(checkboxTable).center().row() add(checkboxTable).center().row()
if (!withoutMods) if (!withoutMods) add(modCheckboxes).row()
modCheckboxes = getModCheckboxes()
add(modCheckboxes).row()
pack() pack()
} }
@ -150,7 +151,7 @@ class GameOptionsTable(
gameParameters.baseRuleset gameParameters.baseRuleset
) { newBaseRuleset -> ) { newBaseRuleset ->
val previousSelection = gameParameters.baseRuleset val previousSelection = gameParameters.baseRuleset
if (newBaseRuleset == gameParameters.baseRuleset) return@addSelectBox null if (newBaseRuleset == gameParameters.baseRuleset) return@addSelectBox null
// Check if this mod is well-defined // Check if this mod is well-defined
val baseRulesetErrors = RulesetCache[newBaseRuleset]!!.checkModLinks() val baseRulesetErrors = RulesetCache[newBaseRuleset]!!.checkModLinks()
@ -172,10 +173,7 @@ class GameOptionsTable(
val toastMessage = val toastMessage =
"This base ruleset is not compatible with the previously selected\nextension mods. They have been disabled.".tr() "This base ruleset is not compatible with the previously selected\nextension mods. They have been disabled.".tr()
ToastPopup(toastMessage, previousScreen as CameraStageBaseScreen, 5000L) ToastPopup(toastMessage, previousScreen as CameraStageBaseScreen, 5000L)
// _technically_, [modCheckBoxes] can be [null] at this point,
// but only if you change the option while the table is still loading,
// but the timeframe for that is so small I'm just going to ignore that
modCheckboxes!!.disableAllCheckboxes() modCheckboxes!!.disableAllCheckboxes()
} else if (modLinkErrors.isWarnUser()) { } else if (modLinkErrors.isWarnUser()) {
val toastMessage = val toastMessage =