diff --git a/src/main/java/me/cortex/voxy/client/core/VoxyRenderSystem.java b/src/main/java/me/cortex/voxy/client/core/VoxyRenderSystem.java index 3dc19bdc..be7d1c0b 100644 --- a/src/main/java/me/cortex/voxy/client/core/VoxyRenderSystem.java +++ b/src/main/java/me/cortex/voxy/client/core/VoxyRenderSystem.java @@ -253,6 +253,8 @@ public class VoxyRenderSystem { try {this.renderer.shutdown();this.chunkBoundRenderer.free();} catch (Exception e) {Logger.error("Error shutting down renderer", e);} Logger.info("Shutting down post processor"); if (this.postProcessing!=null){try {this.postProcessing.shutdown();} catch (Exception e) {Logger.error("Error shutting down post processor", e);}} + Logger.info("Flushing download stream"); + DownloadStream.INSTANCE.flushWaitClear(); //Release hold on the world this.worldIn.releaseRef(); diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/HierarchicalOcclusionTraverser.java b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/HierarchicalOcclusionTraverser.java index 476a226b..593df4b4 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/HierarchicalOcclusionTraverser.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/HierarchicalOcclusionTraverser.java @@ -12,6 +12,7 @@ import me.cortex.voxy.client.core.rendering.building.RenderGenerationService; import me.cortex.voxy.client.core.rendering.util.DownloadStream; import me.cortex.voxy.client.core.rendering.util.PrintfDebugUtil; import me.cortex.voxy.client.core.rendering.util.UploadStream; +import me.cortex.voxy.common.Logger; import me.cortex.voxy.common.util.MemoryBuffer; import me.cortex.voxy.common.world.WorldEngine; import org.lwjgl.system.MemoryUtil; @@ -320,7 +321,8 @@ public class HierarchicalOcclusionTraverser { private void forwardDownloadResult(long ptr, long size) { int count = MemoryUtil.memGetInt(ptr);ptr += 8;//its 8 since we need to skip the second value (which is empty) if (count < 0 || count > 50000) { - throw new IllegalStateException("Count unexpected extreme value: " + count); + Logger.error(new IllegalStateException("Count unexpected extreme value: " + count)); + return; } if (count > (this.requestBuffer.size()>>3)-1) { //This should not break the synchonization between gpu and cpu as in the traversal shader is diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/util/DownloadStream.java b/src/main/java/me/cortex/voxy/client/core/rendering/util/DownloadStream.java index 8a62bc64..04a6b6c1 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/util/DownloadStream.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/util/DownloadStream.java @@ -149,6 +149,21 @@ public class DownloadStream { } //Synchonize force flushes everything + public void waitDiscard() { + glFinish(); + var fence = new GlFence(); + glFinish(); + while (!fence.signaled()) + Thread.onSpinWait(); + fence.free(); + while (!this.frames.isEmpty()) { + var frame = this.frames.pop(); + while (!frame.fence.signaled()) Thread.onSpinWait(); + frame.allocations.forEach(this.allocationArena::free); + frame.fence.free(); + } + } + public void flushWaitClear() { glFinish(); this.tick();