diff --git a/core/src/com/unciv/MainMenuScreen.kt b/core/src/com/unciv/MainMenuScreen.kt index 462b26b0dc..618625d4f7 100644 --- a/core/src/com/unciv/MainMenuScreen.kt +++ b/core/src/com/unciv/MainMenuScreen.kt @@ -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.Table import com.badlogic.gdx.utils.Align +import com.unciv.logic.GameInfo import com.unciv.logic.GameSaver import com.unciv.logic.GameStarter import com.unciv.logic.map.mapgenerator.MapGenerator @@ -165,15 +166,25 @@ class MainMenuScreen: CameraStageBaseScreen() { private fun autoLoadGame() { - try { - game.loadGame(autosave) - dispose() - } - 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 - ResponsePopup("Cannot resume game!", this) + ResponsePopup("Loading...", this) + thread { // Load game from file to class on separate thread to avoid ANR... + val savedGame: GameInfo + try { + savedGame = GameSaver.loadGameByName(autosave) + } catch (outOfMemory: OutOfMemoryError) { + ResponsePopup("Not enough memory on phone to load game!", this) + return@thread + } + + 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) + } + + } } }