mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
world renderer: fix crash when lowering render distance
This commit is contained in:
parent
7c0c136db3
commit
496c16a470
@ -27,7 +27,7 @@ object BlockProfileManager : ProfileManager<BlockProfile> {
|
|||||||
|
|
||||||
override fun createDefaultProfile(name: String): BlockProfile {
|
override fun createDefaultProfile(name: String): BlockProfile {
|
||||||
currentLoadingPath = name
|
currentLoadingPath = name
|
||||||
val profile = BlockProfile("Default block profile")
|
val profile = BlockProfile("Default block profile")
|
||||||
currentLoadingPath = null
|
currentLoadingPath = null
|
||||||
profiles[name] = profile
|
profiles[name] = profile
|
||||||
|
|
||||||
|
|||||||
@ -258,23 +258,27 @@ class WorldRenderer(
|
|||||||
|
|
||||||
connection.registerEvent(CallbackEventInvoker.of<ViewDistanceChangeEvent> {
|
connection.registerEvent(CallbackEventInvoker.of<ViewDistanceChangeEvent> {
|
||||||
// Unload all chunks(-sections) that are out of view distance
|
// Unload all chunks(-sections) that are out of view distance
|
||||||
|
|
||||||
|
queueLock.lock()
|
||||||
|
culledQueueLock.lock()
|
||||||
|
meshesToLoadLock.lock()
|
||||||
meshesToUnloadLock.lock()
|
meshesToUnloadLock.lock()
|
||||||
|
loadedMeshesLock.lock()
|
||||||
|
val loadedMeshesToRemove: MutableSet<Vec2i> = mutableSetOf()
|
||||||
for ((chunkPosition, sections) in loadedMeshes) {
|
for ((chunkPosition, sections) in loadedMeshes) {
|
||||||
if (isChunkVisible(chunkPosition)) {
|
if (isChunkVisible(chunkPosition)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
loadedMeshesToRemove += chunkPosition
|
||||||
for (mesh in sections.values) {
|
for (mesh in sections.values) {
|
||||||
|
if (mesh in meshesToUnload) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
meshesToUnload += mesh
|
meshesToUnload += mesh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
meshesToUnloadLock.unlock()
|
loadedMeshes -= loadedMeshesToRemove
|
||||||
|
|
||||||
|
|
||||||
queueLock.lock()
|
|
||||||
queue.removeAll { !isChunkVisible(it.chunkPosition) }
|
|
||||||
queueLock.unlock()
|
|
||||||
|
|
||||||
culledQueueLock.lock()
|
|
||||||
val toRemove: MutableSet<Vec2i> = mutableSetOf()
|
val toRemove: MutableSet<Vec2i> = mutableSetOf()
|
||||||
for ((chunkPosition, _) in culledQueue) {
|
for ((chunkPosition, _) in culledQueue) {
|
||||||
if (isChunkVisible(chunkPosition)) {
|
if (isChunkVisible(chunkPosition)) {
|
||||||
@ -283,7 +287,22 @@ class WorldRenderer(
|
|||||||
toRemove += chunkPosition
|
toRemove += chunkPosition
|
||||||
}
|
}
|
||||||
culledQueue -= toRemove
|
culledQueue -= toRemove
|
||||||
|
|
||||||
|
queue.removeAll { !isChunkVisible(it.chunkPosition) }
|
||||||
|
|
||||||
|
meshesToLoad.removeAll { !isChunkVisible(it.chunkPosition) }
|
||||||
|
|
||||||
|
for (task in preparingTasks.toMutableSet()) {
|
||||||
|
if (!isChunkVisible(task.chunkPosition)) {
|
||||||
|
task.runnable.interrupt()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loadedMeshesLock.unlock()
|
||||||
|
queueLock.unlock()
|
||||||
culledQueueLock.unlock()
|
culledQueueLock.unlock()
|
||||||
|
meshesToLoadLock.unlock()
|
||||||
|
meshesToUnloadLock.unlock()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,6 +373,7 @@ class WorldRenderer(
|
|||||||
for (mesh in meshes.values) {
|
for (mesh in meshes.values) {
|
||||||
meshesToUnload += mesh
|
meshesToUnload += mesh
|
||||||
}
|
}
|
||||||
|
loadedMeshes -= chunkPosition
|
||||||
}
|
}
|
||||||
|
|
||||||
loadedMeshesLock.unlock()
|
loadedMeshesLock.unlock()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user