yairm210 / Unciv

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

Memory leak through setNewRuleset #9325

Closed SomeTroglodyte closed 1 year ago

SomeTroglodyte commented 1 year ago

Platform: Desktop Version: 4.6.8 (Build 858) Rulesets: [Policy mod, Brave New World, Historica, Community Maps, DeCiv Redux, Thin Bubbly Borders, Leader Mission, Barbarian xp farm, Powerful GDR, More Luxuries, More Fauna And Flora, Honor Wonders, Civ V - Vanilla, No Fog Of War, Epic of Fantasy, Civ6 Tileset, Alpha Frontier, Better Pantheons, Ancient Civilizations, Civ V - Gods & Kings, More Natural Wonders, The Great Unciv Rework, Extra Resources, Better ruins, Logicians] Last Screen: com.unciv.ui.screens.mainmenuscreen.MainMenuScreen


OS: Windows 10 Java: Eclipse Adoptium Temurin-17.0.6+10 Max Memory: 8112 MB


Message:

com.badlogic.gdx.utils.GdxRuntimeException: Unable to allocate memory for pixmap: 1024x1024, rgba8888
    at com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.<init>(Gdx2DPixmap.java:138)
    at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
    at com.badlogic.gdx.graphics.g2d.PixmapPacker$Page.<init>(PixmapPacker.java:476)
    at com.badlogic.gdx.graphics.g2d.PixmapPacker$GuillotineStrategy$GuillotinePage.<init>(PixmapPacker.java:624)
    at com.badlogic.gdx.graphics.g2d.PixmapPacker$GuillotineStrategy.pack(PixmapPacker.java:550)
    at com.badlogic.gdx.graphics.g2d.PixmapPacker.pack(PixmapPacker.java:250)
    at com.badlogic.gdx.graphics.g2d.PixmapPacker.pack(PixmapPacker.java:156)
    at com.unciv.ui.components.NativeBitmapFontData.getGlyph(Fonts.kt:119)
    at com.unciv.ui.components.NativeBitmapFontData.<init>(Fonts.kt:102)
    at com.unciv.ui.components.FontImplementation$DefaultImpls.getBitmapFont(Fonts.kt:35)
    at com.unciv.app.desktop.DesktopFont.getBitmapFont(DesktopFont.kt:13)
    at com.unciv.ui.components.Fonts.resetFont(Fonts.kt:207)
    at com.unciv.ui.images.ImageGetter.setNewRuleset(ImageGetter.kt:78)
    at com.unciv.ui.screens.mainmenuscreen.MainMenuScreen$startBackgroundMapGeneration$1$2.invokeSuspend(MainMenuScreen.kt:229)
    at com.unciv.ui.screens.mainmenuscreen.MainMenuScreen$startBackgroundMapGeneration$1$2.invoke(MainMenuScreen.kt)
    at com.unciv.ui.screens.mainmenuscreen.MainMenuScreen$startBackgroundMapGeneration$1$2.invoke(MainMenuScreen.kt)
    at com.unciv.utils.concurrency.ConcurrencyKt$launchCrashHandling$1.invokeSuspend(Concurrency.kt:83)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at com.unciv.utils.concurrency.CrashHandlingDispatcher$dispatch$1.invoke(Concurrency.kt:164)
    at com.unciv.utils.concurrency.CrashHandlingDispatcher$dispatch$1.invoke(Concurrency.kt:164)
    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.concurrency.CrashHandlingDispatcher.dispatch$lambda$0(Concurrency.kt:164)
    at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.loop(Lwjgl3Application.java:208)
    at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:166)
    at com.unciv.app.desktop.DesktopLauncher.main(DesktopLauncher.kt:80)

Current master with MainScreen mapReplaceDelay reduced to 2, compiled to jar, run with no arguments. Left sitting, crashes somewhere between 15 and 60 minutes. No success so far catching it in the debugger as it brings down Studio with it.

My guess: Has something to do with NativeBitmapFontData implementing Disposable, but its dispose never runs. (And after fixing that, we should make startBackgroundMapGeneration use one ruleset throughout a MainMenuScreen lifetime, and make enableEasterEggs == false avoid the ruleset creation properly)

yairm210 commented 1 year ago

Good catch!