Solved ANR when loading large games from the load screen

This commit is contained in:
Yair Morgenstern 2020-12-16 12:27:01 +02:00
parent 5e157b66d0
commit 925e092629
2 changed files with 61 additions and 55 deletions

View File

@ -38,10 +38,14 @@ class LoadGameScreen(previousScreen:CameraStageBaseScreen) : PickerScreen() {
topTable.add(rightSideTable)
rightSideButton.onClick {
ToastPopup("Loading...", this)
thread {
try {
UncivGame.Current.loadGame(selectedSave)
}
catch (ex:Exception){
// This is what can lead to ANRs - reading the file and setting the transients, that's why this is in another thread
val loadedGame = GameSaver.loadGameByName(selectedSave)
Gdx.app.postRunnable { UncivGame.Current.loadGame(loadedGame) }
} catch (ex: Exception) {
Gdx.app.postRunnable {
val cantLoadGamePopup = Popup(this)
cantLoadGamePopup.addGoodSizedLabel("It looks like your saved game can't be loaded!").row()
if (ex is UncivShowableException && ex.localizedMessage != null) {
@ -59,6 +63,8 @@ class LoadGameScreen(previousScreen:CameraStageBaseScreen) : PickerScreen() {
}
}
}
}
}
}