mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
Resolved #3048 - Fixed ANRs on 'Resume' on huge save files
This commit is contained in:
parent
bf2742350d
commit
baa7044fd1
@ -7,6 +7,7 @@ import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
|||||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
|
import com.unciv.logic.GameInfo
|
||||||
import com.unciv.logic.GameSaver
|
import com.unciv.logic.GameSaver
|
||||||
import com.unciv.logic.GameStarter
|
import com.unciv.logic.GameStarter
|
||||||
import com.unciv.logic.map.mapgenerator.MapGenerator
|
import com.unciv.logic.map.mapgenerator.MapGenerator
|
||||||
@ -165,15 +166,25 @@ class MainMenuScreen: CameraStageBaseScreen() {
|
|||||||
|
|
||||||
|
|
||||||
private fun autoLoadGame() {
|
private fun autoLoadGame() {
|
||||||
try {
|
ResponsePopup("Loading...", this)
|
||||||
game.loadGame(autosave)
|
thread { // Load game from file to class on separate thread to avoid ANR...
|
||||||
dispose()
|
val savedGame: GameInfo
|
||||||
}
|
try {
|
||||||
catch (outOfMemory:OutOfMemoryError){
|
savedGame = GameSaver.loadGameByName(autosave)
|
||||||
ResponsePopup("Not enough memory on phone to load game!", this)
|
} catch (outOfMemory: OutOfMemoryError) {
|
||||||
}
|
ResponsePopup("Not enough memory on phone to load game!", this)
|
||||||
catch (ex: Exception) { // silent fail if we can't read the autosave
|
return@thread
|
||||||
ResponsePopup("Cannot resume game!", this)
|
}
|
||||||
|
|
||||||
|
Gdx.app.postRunnable { /// ... and load it into the screen on main thread for GL context
|
||||||
|
try {
|
||||||
|
game.loadGame(savedGame)
|
||||||
|
dispose()
|
||||||
|
} catch (ex: Exception) { // silent fail if we can't read the autosave
|
||||||
|
ResponsePopup("Cannot resume game!", this)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user