From 625c4c91390d1df4717dc73250a776da2498cd14 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Wed, 16 Jun 2021 06:33:37 +0200 Subject: [PATCH] Fix uninitialized lateinit access in TradeOffer (#4159) --- core/src/com/unciv/logic/trade/TradeOffer.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/core/src/com/unciv/logic/trade/TradeOffer.kt b/core/src/com/unciv/logic/trade/TradeOffer.kt index fa4087c98e..698bdc5a2c 100644 --- a/core/src/com/unciv/logic/trade/TradeOffer.kt +++ b/core/src/com/unciv/logic/trade/TradeOffer.kt @@ -12,12 +12,17 @@ data class TradeOffer(val name:String, val type:TradeType, var amount:Int = 1, v init { // Duration needs to be part of the variables defined in the primary constructor, // so that it will be copied over with the automatically generated copy() - val gameSpeed = UncivGame.Current.gameInfo.gameParameters.gameSpeed - duration = when { - type.isImmediate -> -1 // -1 for offers that are immediate (e.g. gold transfer) - name == Constants.peaceTreaty -> 10 - gameSpeed == GameSpeed.Quick -> 25 - else -> (30 * gameSpeed.modifier).toInt() + + duration = + if (type.isImmediate) -1 // -1 for offers that are immediate (e.g. gold transfer) + else { + // Do *not* access UncivGame.Current.gameInfo in the default constructor! + val gameSpeed = UncivGame.Current.gameInfo.gameParameters.gameSpeed + when { + name == Constants.peaceTreaty -> 10 + gameSpeed == GameSpeed.Quick -> 25 + else -> (30 * gameSpeed.modifier).toInt() + } } }