From dcdb0ca8921acb0e79df800a10a04e4e35ca6b66 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 9 Feb 2022 18:02:52 +0200 Subject: [PATCH] Loading a new game while nextTurn is running no longer reverts you to that game --- core/src/com/unciv/ui/worldscreen/WorldScreen.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 008df3580c..88517d7408 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -636,12 +636,13 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas if (consoleLog) println("\nNext turn starting " + Date().formatDate()) val startTime = System.currentTimeMillis() - val gameInfoClone = gameInfo.clone() + val originalGameInfo = gameInfo + val gameInfoClone = originalGameInfo.clone() gameInfoClone.setTransients() // this can get expensive on large games, not the clone itself gameInfoClone.nextTurn() - if (gameInfo.gameParameters.isOnlineMultiplayer) { + if (originalGameInfo.gameParameters.isOnlineMultiplayer) { try { OnlineMultiplayer().tryUploadGame(gameInfoClone, withPreview = true) } catch (ex: Exception) { @@ -657,6 +658,9 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas } } + if (game.gameInfo != originalGameInfo) // while this was turning we loaded another game + return@crashHandlingThread + game.gameInfo = gameInfoClone if (consoleLog) println("Next turn took ${System.currentTimeMillis()-startTime}ms") @@ -667,7 +671,6 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas // do this on main thread - it's the only one that has a GL context to create images from postCrashHandlingRunnable { - if (gameInfoClone.currentPlayerCiv.civName != viewingCiv.civName && !gameInfoClone.gameParameters.isOnlineMultiplayer) game.setScreen(PlayerReadyScreen(gameInfoClone, gameInfoClone.getCurrentPlayerCivilization()))