From f6e432691d62557d633705c45f9ee987a34dbaaf Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Tue, 23 Apr 2024 23:00:05 +0200 Subject: [PATCH] Fix: Potential crash on new game after deleting a base ruleset mod (#11508) * Fix: Potential crash on new game after deleting a base ruleset mod * Review --- .../unciv/ui/screens/newgamescreen/ModCheckboxTable.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/ui/screens/newgamescreen/ModCheckboxTable.kt b/core/src/com/unciv/ui/screens/newgamescreen/ModCheckboxTable.kt index d0a0b3297a..a85a1615f1 100644 --- a/core/src/com/unciv/ui/screens/newgamescreen/ModCheckboxTable.kt +++ b/core/src/com/unciv/ui/screens/newgamescreen/ModCheckboxTable.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx import com.badlogic.gdx.scenes.scene2d.ui.CheckBox import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener +import com.unciv.models.metadata.BaseRuleset import com.unciv.models.metadata.GameParameters import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.RulesetCache @@ -79,12 +80,15 @@ class ModCheckboxTable( deselectIncompatibleMods(null) } - fun setBaseRuleset(newBaseRuleset: String) { - baseRulesetName = newBaseRuleset + fun setBaseRuleset(newBaseRulesetName: String) { + val newBaseRuleset = RulesetCache[newBaseRulesetName] + // We're calling this from init, baseRuleset is lateinit, and the mod may have been deleted: Must make sure baseRuleset is initialized + ?: return setBaseRuleset(BaseRuleset.Civ_V_GnK.fullName) + baseRulesetName = newBaseRulesetName + baseRuleset = newBaseRuleset savedModcheckResult = null clear() mods.clear() // We'll regenerate this from checked widgets - baseRuleset = RulesetCache[newBaseRuleset] ?: return val compatibleMods = modWidgets .filter { ModCompatibility.meetsBaseRequirements(it.mod, baseRuleset) }