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)
This commit is contained in:
SomeTroglodyte 2024-05-16 06:03:59 +02:00 committed by GitHub
parent 428edfb12a
commit 5238ff23e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View File

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

View File

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