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()
defaults().pad(5f)
// We assign this first to make sure addBaseRulesetSelectBox doesn't reference a null object
if (!withoutMods) modCheckboxes = getModCheckboxes()
add(Table().apply {
defaults().pad(5f)
addBaseRulesetSelectBox()
@ -59,9 +62,7 @@ class GameOptionsTable(
checkboxTable.addReligionCheckbox(cityStateSlider)
add(checkboxTable).center().row()
if (!withoutMods)
modCheckboxes = getModCheckboxes()
add(modCheckboxes).row()
if (!withoutMods) add(modCheckboxes).row()
pack()
}
@ -150,7 +151,7 @@ class GameOptionsTable(
gameParameters.baseRuleset
) { newBaseRuleset ->
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
val baseRulesetErrors = RulesetCache[newBaseRuleset]!!.checkModLinks()
@ -172,10 +173,7 @@ class GameOptionsTable(
val toastMessage =
"This base ruleset is not compatible with the previously selected\nextension mods. They have been disabled.".tr()
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()
} else if (modLinkErrors.isWarnUser()) {
val toastMessage =