From 5238ff23e1be7eb5dd219234e82341cfd5112bd9 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Thu, 16 May 2024 06:03:59 +0200 Subject: [PATCH] Fix crash when a starting unit has a random conditional (#11596) * Harden StateForConditionals.hashCode against uninitialized lateinit * Fix potential crash in new game screen (leftover debug assert) --- .../com/unciv/models/ruleset/unique/StateForConditionals.kt | 6 ++++-- .../com/unciv/ui/screens/newgamescreen/ModCheckboxTable.kt | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/models/ruleset/unique/StateForConditionals.kt b/core/src/com/unciv/models/ruleset/unique/StateForConditionals.kt index 91a11cd438..3de770a774 100644 --- a/core/src/com/unciv/models/ruleset/unique/StateForConditionals.kt +++ b/core/src/com/unciv/models/ruleset/unique/StateForConditionals.kt @@ -48,8 +48,10 @@ data class StateForConditionals( fun Civilization?.hash() = this?.civName?.hashCode() ?: 0 fun City?.hash() = this?.id?.hashCode() ?: 0 fun Tile?.hash() = this?.position?.hashCode() ?: 0 - fun MapUnit?.hash() = (this?.name?.hashCode() ?: 0) + 17 * this?.currentTile.hash() - fun ICombatant?.hash() = (this?.getName()?.hashCode() ?: 0) + 17 * this?.getTile().hash() + fun MapUnit?.hash() = if (this == null) 0 else name.hashCode() + (if (hasTile()) 17 * currentTile.hash() else 0) + fun ICombatant?.hash() = if (this == null) 0 + else if (this is MapUnitCombatant) unit.hash() // line only serves as `lateinit currentTile not initialized` guard + else getName().hashCode() + 17 * getTile().hash() fun CombatAction?.hash() = this?.name?.hashCode() ?: 0 fun Region?.hash() = this?.rect?.hashCode() ?: 0 diff --git a/core/src/com/unciv/ui/screens/newgamescreen/ModCheckboxTable.kt b/core/src/com/unciv/ui/screens/newgamescreen/ModCheckboxTable.kt index a85a1615f1..fe3de4ee60 100644 --- a/core/src/com/unciv/ui/screens/newgamescreen/ModCheckboxTable.kt +++ b/core/src/com/unciv/ui/screens/newgamescreen/ModCheckboxTable.kt @@ -212,7 +212,7 @@ class ModCheckboxTable( private fun disableIncompatibleMods() { for (modWidget in modWidgets) { val enable = ModCompatibility.meetsAllRequirements(modWidget.mod, baseRuleset, getSelectedMods()) - assert(enable || !modWidget.widget.isChecked) { "Mod compatibility conflict: Trying to disable ${modWidget.mod.name} while it is selected" } + if (!enable && modWidget.widget.isChecked) modWidget.widget.isChecked = false // mod widgets can't, but selecting a map can cause this situation modWidget.widget.isDisabled = !enable // isEnabled is only for TextButtons } }