mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-10 13:51:53 +09:00
no more access violation from freeing already freed memory
This commit is contained in:
@@ -82,6 +82,10 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
|
|||||||
*/
|
*/
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
printdbg(this, "Thank you for properly disposing the world!")
|
printdbg(this, "Thank you for properly disposing the world!")
|
||||||
|
printdbg(this, "dispose called by")
|
||||||
|
Thread.currentThread().stackTrace.forEach {
|
||||||
|
printdbg(this, "--> $it")
|
||||||
|
}
|
||||||
|
|
||||||
world.dispose()
|
world.dispose()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -321,6 +321,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
|
|||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
logo.texture.dispose()
|
logo.texture.dispose()
|
||||||
uiMenu.dispose()
|
uiMenu.dispose()
|
||||||
|
demoWorld.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ open class BlockLayer(val width: Int, val height: Int) : Disposable {
|
|||||||
unsafe = unsafeConstructor.newInstance()
|
unsafe = unsafeConstructor.newInstance()
|
||||||
}
|
}
|
||||||
private var unsafeArrayInitialised = false
|
private var unsafeArrayInitialised = false
|
||||||
|
private var unsafeArrayDestroyed = false
|
||||||
|
|
||||||
private var layerPtr = unsafe.allocateMemory(width * height * BYTES_PER_BLOCK.toLong())
|
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)
|
fun isInBound(x: Int, y: Int) = (x >= 0 && y >= 0 && x < width && y < height)
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
unsafe.freeMemory(layerPtr)
|
if (!unsafeArrayDestroyed) {
|
||||||
printdbg(this, "BlockLayer successfully freed")
|
unsafe.freeMemory(layerPtr)
|
||||||
|
unsafeArrayDestroyed = true
|
||||||
|
printdbg(this, "BlockLayer successfully freed")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
Reference in New Issue
Block a user