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
This commit is contained in:
SomeTroglodyte 2024-04-23 23:00:05 +02:00 committed by GitHub
parent 5c6d9171c4
commit f6e432691d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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) }