mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 17:07:55 -04:00
Mesh: unload data if not loaded yet
That should fix some memory leaks (especially in entity rendering)
This commit is contained in:
parent
2d18be7ee4
commit
00ab71e73b
@ -39,10 +39,14 @@ class ChunkMesher(
|
|||||||
}
|
}
|
||||||
val sectionNeighbours = ChunkUtil.getDirectNeighbours(neighbours, item.chunk, item.section.sectionHeight)
|
val sectionNeighbours = ChunkUtil.getDirectNeighbours(neighbours, item.chunk, item.section.sectionHeight)
|
||||||
val mesh = ChunkMeshes(renderer.context, item.chunkPosition, item.sectionHeight, item.section.smallMesh)
|
val mesh = ChunkMeshes(renderer.context, item.chunkPosition, item.sectionHeight, item.section.smallMesh)
|
||||||
solid.mesh(item.chunkPosition, item.sectionHeight, item.chunk, item.section, neighbours, sectionNeighbours, mesh)
|
try {
|
||||||
|
solid.mesh(item.chunkPosition, item.sectionHeight, item.chunk, item.section, neighbours, sectionNeighbours, mesh)
|
||||||
|
|
||||||
if (item.section.blocks.fluidCount > 0) {
|
if (item.section.blocks.fluidCount > 0) {
|
||||||
fluid.mesh(item.chunkPosition, item.sectionHeight, item.chunk, item.section, neighbours, sectionNeighbours, mesh)
|
fluid.mesh(item.chunkPosition, item.sectionHeight, item.chunk, item.section, neighbours, sectionNeighbours, mesh)
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
mesh.unload()
|
||||||
}
|
}
|
||||||
|
|
||||||
return mesh
|
return mesh
|
||||||
|
@ -135,7 +135,6 @@ class HitboxFeature(renderer: EntityRenderer<*>) : EntityRenderFeature(renderer)
|
|||||||
override fun unload() {
|
override fun unload() {
|
||||||
val mesh = this.mesh ?: return
|
val mesh = this.mesh ?: return
|
||||||
this.mesh = null
|
this.mesh = null
|
||||||
if (mesh.state != Mesh.MeshStates.LOADED) return
|
|
||||||
renderer.renderer.queue += { mesh.unload() }
|
renderer.renderer.queue += { mesh.unload() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,6 @@ open class BillboardTextFeature(
|
|||||||
val mesh = this.mesh ?: return
|
val mesh = this.mesh ?: return
|
||||||
this.mesh = null
|
this.mesh = null
|
||||||
this.info = null
|
this.info = null
|
||||||
if (mesh.state != Mesh.MeshStates.LOADED) return
|
|
||||||
renderer.renderer.queue += { mesh.unload() }
|
renderer.renderer.queue += { mesh.unload() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,8 +83,11 @@ abstract class Mesh(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun unload() {
|
fun unload() {
|
||||||
check(state == MeshStates.LOADED) { "Can not unload $state mesh!" }
|
when (state) {
|
||||||
buffer.unload()
|
MeshStates.LOADED -> buffer.unload()
|
||||||
|
MeshStates.PREPARING, MeshStates.FINISHED -> _data?.unload()
|
||||||
|
else -> throw IllegalStateException("Mesh is already unloaded")
|
||||||
|
}
|
||||||
state = MeshStates.UNLOADED
|
state = MeshStates.UNLOADED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user