yairm210 / Unciv

Open-source Android/Desktop remake of Civ V
Mozilla Public License 2.0
8.5k stars 1.58k forks source link

fail to memorize a new file #10483

Closed doyouean closed 11 months ago

doyouean commented 11 months ago

Platform: Android Version: 4.8.15 (Build 925) Rulesets: [LOTR Unciv, Civ V - Vanilla, Brave New World, Civ V - Gods & Kings, DeCiv Redux, Community Maps, Civ6 mod, 5Hex Tileset, Alpha Frontier] Last Screen: com.unciv.ui.screens.savescreens.SaveGameScreen


Device Model: SM-M115F API Level: 31


Message:

java.lang.OutOfMemoryError: Failed to allocate a 9443680 byte allocation with 3728728 free bytes and 3641KB until OOM, target footprint 268435456, growth limit 268435456
    at java.lang.StringFactory.newStringFromChars(StringFactory.java:112)
    at java.lang.StringBuffer.toString(StringBuffer.java:671)
    at java.io.StringWriter.toString(StringWriter.java:218)
    at com.badlogic.gdx.utils.Json.toJson(Json.java:239)
    at com.badlogic.gdx.utils.Json.toJson(Json.java:227)
    at com.unciv.logic.files.UncivFiles$Companion.gameInfoToString(UncivFiles.kt:380)
    at com.unciv.logic.files.UncivFiles$Companion.gameInfoToString$default(UncivFiles.kt:376)
    at com.unciv.logic.files.UncivFiles.saveGame(UncivFiles.kt:161)
    at com.unciv.logic.files.UncivFiles.saveGame(UncivFiles.kt:151)
    at com.unciv.ui.screens.savescreens.SaveGameScreen$saveGame$1.invokeSuspend(SaveGameScreen.kt:122)
    at com.unciv.ui.screens.savescreens.SaveGameScreen$saveGame$1.invoke(Unknown Source:8)
    at com.unciv.ui.screens.savescreens.SaveGameScreen$saveGame$1.invoke(Unknown Source:4)
    at com.unciv.utils.ConcurrencyKt$launchCrashHandling$1.invokeSuspend(Concurrency.kt:87)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
    at com.unciv.utils.CrashHandlingDispatcher$dispatch$1.invoke(Concurrency.kt:173)
    at com.unciv.utils.CrashHandlingDispatcher$dispatch$1.invoke(Concurrency.kt:173)
    at com.unciv.ui.crashhandling.CrashHandlingExtensionsKt$wrapCrashHandling$1.invoke(CrashHandlingExtensions.kt:17)
    at com.unciv.ui.crashhandling.CrashHandlingExtensionsKt$wrapCrashHandlingUnit$1.invoke(CrashHandlingExtensions.kt:33)
    at com.unciv.ui.crashhandling.CrashHandlingExtensionsKt$wrapCrashHandlingUnit$1.invoke(CrashHandlingExtensions.kt:33)
    at com.unciv.utils.CrashHandlingDispatcher.dispatch$lambda$0(Concurrency.kt:173)
    at com.unciv.utils.CrashHandlingDispatcher.$r8$lambda$GFMOlD6QMgmLfgwAvPAW33Ob6HE(Unknown Source:0)
    at com.unciv.utils.CrashHandlingDispatcher$$ExternalSyntheticLambda0.run(Unknown Source:2)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
    at java.lang.Thread.run(Thread.java:1012)

Save Mods:

[Civ V - Gods & Kings]

Save Data:

Show Saved Game ``` No save data: java.lang.OutOfMemoryError: Failed to allocate a 9443680 byte allocation with 3599504 free bytes and 3515KB until OOM, target footprint 268435456, growth limit 268435456 ```
SomeTroglodyte commented 11 months ago

And here we are again. All considering, the frequency of OOM issues is actually surprisingly low. That Samsung M11 comes with 3 or 4GB of RAM, but we have no idea how much of that Unciv can actually use. Likely less than 512M.

We do set android:largeHeap="true" - this was the first and for a long time the only influence an App had over its heap size, right? Introduced in Android 3 I believe. Did they add any more methods later??? No idea.

Could we try to display the actual heap size in a crash screen? No idea whether Java's Runtime.getRuntime().maxMemory() such as SystemUtils line 37 does for desktop has any meaning. I'll see later how to get [getMemoryClass()](https://developer.android.com/reference/android/app/ActivityManager#getMemoryClass()) into the crash screen info.

@doyouean - this means more or less your map is too big, or you are using an "expensive" (in terms of memory) graphics mod via "permanent audiovisual". This paragraph on Android's developer documentation basically confirms - we don't have control, your device limits us.

Wait - "permanent audiovisual" - we should include that in our crash screen info too.

yairm210 commented 11 months ago

We've done all we can here - memory limits will be hit by players with huge maps on Android, and we do warn against it, but this is better than artificially limiting sizes for those players who can effectively run gigantic maps.

SomeTroglodyte commented 11 months ago

And I learned something - even on my 8GB Mi10T, Unciv only gets 512MB for its heap. Am Surprised.