diff --git a/src/net/torvald/terrarum/IngameInstance.kt b/src/net/torvald/terrarum/IngameInstance.kt index c2be28a04..cf7e4df60 100644 --- a/src/net/torvald/terrarum/IngameInstance.kt +++ b/src/net/torvald/terrarum/IngameInstance.kt @@ -82,6 +82,10 @@ open class IngameInstance(val batch: SpriteBatch) : Screen { */ override fun dispose() { printdbg(this, "Thank you for properly disposing the world!") + printdbg(this, "dispose called by") + Thread.currentThread().stackTrace.forEach { + printdbg(this, "--> $it") + } world.dispose() } diff --git a/src/net/torvald/terrarum/TitleScreen.kt b/src/net/torvald/terrarum/TitleScreen.kt index dab98b5ad..2900628c7 100644 --- a/src/net/torvald/terrarum/TitleScreen.kt +++ b/src/net/torvald/terrarum/TitleScreen.kt @@ -321,6 +321,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen { override fun dispose() { logo.texture.dispose() uiMenu.dispose() + demoWorld.dispose() } diff --git a/src/net/torvald/terrarum/gameworld/BlockLayer.kt b/src/net/torvald/terrarum/gameworld/BlockLayer.kt index 9ca518ff7..fdca503c7 100644 --- a/src/net/torvald/terrarum/gameworld/BlockLayer.kt +++ b/src/net/torvald/terrarum/gameworld/BlockLayer.kt @@ -16,6 +16,7 @@ open class BlockLayer(val width: Int, val height: Int) : Disposable { unsafe = unsafeConstructor.newInstance() } private var unsafeArrayInitialised = false + private var unsafeArrayDestroyed = false private var layerPtr = unsafe.allocateMemory(width * height * BYTES_PER_BLOCK.toLong()) @@ -135,8 +136,11 @@ open class BlockLayer(val width: Int, val height: Int) : Disposable { fun isInBound(x: Int, y: Int) = (x >= 0 && y >= 0 && x < width && y < height) override fun dispose() { - unsafe.freeMemory(layerPtr) - printdbg(this, "BlockLayer successfully freed") + if (!unsafeArrayDestroyed) { + unsafe.freeMemory(layerPtr) + unsafeArrayDestroyed = true + printdbg(this, "BlockLayer successfully freed") + } } companion object {