mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 13:49:54 +07:00
Wait for autosave thread while closing (#2580)
This commit is contained in:
@ -158,15 +158,23 @@ class UncivGame(
|
|||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
cancelDiscordEvent?.invoke()
|
cancelDiscordEvent?.invoke()
|
||||||
|
|
||||||
|
// Log still running threads (should be only this one and "DestroyJavaVM")
|
||||||
|
val numThreads = Thread.activeCount()
|
||||||
|
val threadList = Array(numThreads) { _ -> Thread() }
|
||||||
|
Thread.enumerate(threadList)
|
||||||
|
|
||||||
if (::gameInfo.isInitialized){
|
if (::gameInfo.isInitialized){
|
||||||
|
val autoSaveThread = threadList.firstOrNull { it.name == "Autosave" }
|
||||||
|
if (autoSaveThread != null && autoSaveThread.isAlive) {
|
||||||
|
// auto save is already in progress (e.g. started by onPause() event)
|
||||||
|
// let's allow it to finish and do not try to autosave second time
|
||||||
|
autoSaveThread.join()
|
||||||
|
} else
|
||||||
GameSaver.autoSaveSingleThreaded(gameInfo) // NO new thread
|
GameSaver.autoSaveSingleThreaded(gameInfo) // NO new thread
|
||||||
settings.save()
|
settings.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log still running threads (should be only this one and "DestroyJavaVM")
|
|
||||||
val numThreads = Thread.activeCount()
|
|
||||||
val threadList = Array<Thread>(numThreads) { _ -> Thread() }
|
|
||||||
Thread.enumerate(threadList)
|
|
||||||
threadList.filter { it !== Thread.currentThread() && it.name != "DestroyJavaVM"}.forEach {
|
threadList.filter { it !== Thread.currentThread() && it.name != "DestroyJavaVM"}.forEach {
|
||||||
println (" Thread ${it.name} still running in UncivGame.dispose().")
|
println (" Thread ${it.name} still running in UncivGame.dispose().")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user