Fixed thread crashes due to concurrent actor changes in multiplayer update popups

This commit is contained in:
Yair Morgenstern
2020-05-03 19:11:07 +03:00
parent b42c8672e1
commit 9397f3608c

View File

@ -231,7 +231,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
try { try {
val latestGame = OnlineMultiplayer().tryDownloadGame(gameInfo.gameId) val latestGame = OnlineMultiplayer().tryDownloadGame(gameInfo.gameId)
if(gameInfo.isUpToDate && gameInfo.currentPlayer==latestGame.currentPlayer) { // we were trying to download this to see when it's our turn...nothing changed if(gameInfo.isUpToDate && gameInfo.currentPlayer==latestGame.currentPlayer) { // we were trying to download this to see when it's our turn...nothing changed
loadingGamePopup.close() Gdx.app.postRunnable { loadingGamePopup.close() }
return@thread return@thread
} }
latestGame.isUpToDate=true latestGame.isUpToDate=true
@ -242,12 +242,14 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
} }
} catch (ex: Exception) { } catch (ex: Exception) {
loadingGamePopup.close() Gdx.app.postRunnable { // otherwise the popups of the screen could be concurrently modified, and we'll get an unhappy thread
val couldntDownloadLatestGame = Popup(this) loadingGamePopup.close()
couldntDownloadLatestGame.addGoodSizedLabel("Couldn't download the latest game state!").row() val couldntDownloadLatestGame = Popup(this)
couldntDownloadLatestGame.addCloseButton() couldntDownloadLatestGame.addGoodSizedLabel("Couldn't download the latest game state!").row()
couldntDownloadLatestGame.addAction(Actions.delay(5f, Actions.run { couldntDownloadLatestGame.close() })) couldntDownloadLatestGame.addCloseButton()
couldntDownloadLatestGame.open() couldntDownloadLatestGame.addAction(Actions.delay(5f, Actions.run { couldntDownloadLatestGame.close() }))
couldntDownloadLatestGame.open()
}
} }
} }
} }