From 8e900a250349e1ea08076e61e298035dcbed21ac Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 6 Feb 2021 20:21:19 +0200 Subject: [PATCH] Hopefully mitigated some weird crashes --- core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt | 6 ++++-- core/src/com/unciv/ui/worldscreen/WorldScreen.kt | 12 +++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt index 55af5662b5..55682750a8 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt @@ -357,8 +357,10 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap } private fun updateTilegroupsForSelectedUnit(unit: MapUnit, playerViewableTilePositions: HashSet) { - - tileGroups[unit.getTile()]!!.selectUnit(unit) + val tileGroup = tileGroups[unit.getTile()] + if (tileGroup == null) return // Entirely unclear when this happens, but this seems to happen since version 520 (3.12.9) + // so maybe has to do with the construction list being asyc? + tileGroup.selectUnit(unit) val isAirUnit = unit.type.isAirUnit() val tilesInMoveRange = diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index f06de2cb6f..31daf815dc 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -37,6 +37,7 @@ import com.unciv.ui.worldscreen.unit.UnitActionsTable import com.unciv.ui.worldscreen.unit.UnitTable import java.util.* import kotlin.concurrent.thread +import kotlin.concurrent.timer class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { val gameInfo = game.gameInfo @@ -145,13 +146,11 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { if (gameInfo.gameParameters.isOnlineMultiplayer && !isPlayersTurn) { // restart the timer stopMultiPlayerRefresher() + // isDaemon = true, in order to not block the app closing - multiPlayerRefresher = Timer("multiPlayerRefresh", true).apply { - schedule(object : TimerTask() { //todo maybe not use timer for web request, from timer docs "Timer tasks should complete quickly." - override fun run() { - loadLatestMultiplayerState() - } - }, 0, 10000) // 10 seconds + // DO NOT use Timer() since this seems to (maybe?) translate to com.badlogic.gdx.utils.Timer? Not sure about this. + multiPlayerRefresher = timer("multiPlayerRefresh", true, period = 10000) { + loadLatestMultiplayerState() } } @@ -249,7 +248,6 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { return } else { //else we found it is the player's turn again, turn off polling and load turn stopMultiPlayerRefresher() - latestGame.isUpToDate = true Gdx.app.postRunnable { game.loadGame(latestGame) } }