world renderer: fix crash when lowering render distance

This commit is contained in:
Bixilon 2021-12-04 19:08:47 +01:00
parent 7c0c136db3
commit 496c16a470
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 28 additions and 8 deletions

View File

@ -27,7 +27,7 @@ object BlockProfileManager : ProfileManager<BlockProfile> {
override fun createDefaultProfile(name: String): BlockProfile {
currentLoadingPath = name
val profile = BlockProfile("Default block profile")
val profile = BlockProfile("Default block profile")
currentLoadingPath = null
profiles[name] = profile

View File

@ -258,23 +258,27 @@ class WorldRenderer(
connection.registerEvent(CallbackEventInvoker.of<ViewDistanceChangeEvent> {
// Unload all chunks(-sections) that are out of view distance
queueLock.lock()
culledQueueLock.lock()
meshesToLoadLock.lock()
meshesToUnloadLock.lock()
loadedMeshesLock.lock()
val loadedMeshesToRemove: MutableSet<Vec2i> = mutableSetOf()
for ((chunkPosition, sections) in loadedMeshes) {
if (isChunkVisible(chunkPosition)) {
continue
}
loadedMeshesToRemove += chunkPosition
for (mesh in sections.values) {
if (mesh in meshesToUnload) {
continue
}
meshesToUnload += mesh
}
}
meshesToUnloadLock.unlock()
loadedMeshes -= loadedMeshesToRemove
queueLock.lock()
queue.removeAll { !isChunkVisible(it.chunkPosition) }
queueLock.unlock()
culledQueueLock.lock()
val toRemove: MutableSet<Vec2i> = mutableSetOf()
for ((chunkPosition, _) in culledQueue) {
if (isChunkVisible(chunkPosition)) {
@ -283,7 +287,22 @@ class WorldRenderer(
toRemove += chunkPosition
}
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()
meshesToLoadLock.unlock()
meshesToUnloadLock.unlock()
})
}
@ -354,6 +373,7 @@ class WorldRenderer(
for (mesh in meshes.values) {
meshesToUnload += mesh
}
loadedMeshes -= chunkPosition
}
loadedMeshesLock.unlock()