From fd4a0fc781f8e5bcef727ba06646e6fb6e0d1900 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 22 Oct 2022 22:04:16 +0300 Subject: [PATCH] Resolved #7876 - fixed memory leak from screenshots --- core/src/com/unciv/UncivGame.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/src/com/unciv/UncivGame.kt b/core/src/com/unciv/UncivGame.kt index 3dbee9ff0e..1b9a907683 100644 --- a/core/src/com/unciv/UncivGame.kt +++ b/core/src/com/unciv/UncivGame.kt @@ -184,10 +184,10 @@ class UncivGame(parameters: UncivGameParameters) : Game() { gameInfo = newGameInfo - if (gameInfo?.gameParameters?.isOnlineMultiplayer == true && gameInfo?.gameParameters?.anyoneCanSpectate == false) { - if (gameInfo!!.civilizations.none { it.playerId == settings.multiplayer.userId }) { - throw UncivShowableException("You are not allowed to spectate!") - } + if (gameInfo?.gameParameters?.isOnlineMultiplayer == true + && gameInfo?.gameParameters?.anyoneCanSpectate == false + && gameInfo!!.civilizations.none { it.playerId == settings.multiplayer.userId }) { + throw UncivShowableException("You are not allowed to spectate!") } initializeResources(prevGameInfo, newGameInfo) @@ -195,10 +195,13 @@ class UncivGame(parameters: UncivGameParameters) : Game() { val isLoadingSameGame = worldScreen != null && prevGameInfo != null && prevGameInfo.gameId == newGameInfo.gameId val worldScreenRestoreState = if (isLoadingSameGame) worldScreen!!.getRestoreState() else null + lateinit var loadingScreen:LoadingScreen + withGLContext { // this is not merged with the below GL context block so that our loading screen gets a chance to show - otherwise // we do it all in one swoop on the same thread and the application just "freezes" without loading screen for the duration. - setScreen(LoadingScreen(getScreen())) + loadingScreen = LoadingScreen(getScreen()) + setScreen(loadingScreen) } return@toplevel withGLContext { @@ -219,6 +222,7 @@ class UncivGame(parameters: UncivGameParameters) : Game() { screenStack.addLast(screenToShow) setScreen(screenToShow) + loadingScreen.dispose() return@withGLContext newWorldScreen }