diff --git a/src/main/java/fi/dy/masa/litematica/render/schematic/BufferBuilderCache.java b/src/main/java/fi/dy/masa/litematica/render/schematic/BufferBuilderCache.java index fb3e8ceec1..9e392a0c6e 100644 --- a/src/main/java/fi/dy/masa/litematica/render/schematic/BufferBuilderCache.java +++ b/src/main/java/fi/dy/masa/litematica/render/schematic/BufferBuilderCache.java @@ -2,16 +2,14 @@ import javax.annotation.Nonnull; import java.util.ArrayList; -import java.util.Map; import java.util.concurrent.ConcurrentHashMap; - import net.minecraft.client.render.BuiltBuffer; import net.minecraft.client.render.RenderLayer; public class BufferBuilderCache implements AutoCloseable { private final ConcurrentHashMap blockBufferBuilders = new ConcurrentHashMap<>(); - private final Map overlayBufferBuilders = new ConcurrentHashMap<>(); + private final ConcurrentHashMap overlayBufferBuilders = new ConcurrentHashMap<>(); protected BufferBuilderCache() { } @@ -32,26 +30,31 @@ protected BufferBuilderPatch getBufferByLayer(RenderLayer layer, @Nonnull Buffer protected BufferBuilderPatch getBufferByOverlay(ChunkRendererSchematicVbo.OverlayRenderType type, @Nonnull BufferAllocatorCache allocators) { - return overlayBufferBuilders.computeIfAbsent(type,(key) -> new BufferBuilderPatch(allocators.getBufferByOverlay(key), key.getDrawMode(), key.getVertexFormat())); + return overlayBufferBuilders.computeIfAbsent(type, (key) -> new BufferBuilderPatch(allocators.getBufferByOverlay(key), key.getDrawMode(), key.getVertexFormat())); } protected void clearAll() { ArrayList buffers; - synchronized (blockBufferBuilders) { + + synchronized (blockBufferBuilders) + { buffers = new ArrayList<>(blockBufferBuilders.values()); blockBufferBuilders.clear(); } - synchronized (overlayBufferBuilders) { + synchronized (overlayBufferBuilders) + { buffers.addAll(overlayBufferBuilders.values()); overlayBufferBuilders.clear(); } - for(BufferBuilderPatch buffer:buffers) { - try{ + for (BufferBuilderPatch buffer:buffers) + { + try { BuiltBuffer built = buffer.endNullable(); - if(built!=null) + if (built != null) built.close(); - } catch (Exception ignored) {} + } + catch (Exception ignored) {} } } diff --git a/src/main/java/fi/dy/masa/litematica/render/schematic/ChunkRendererSchematicVbo.java b/src/main/java/fi/dy/masa/litematica/render/schematic/ChunkRendererSchematicVbo.java index 0408f31b26..e2ea1bd2a6 100644 --- a/src/main/java/fi/dy/masa/litematica/render/schematic/ChunkRendererSchematicVbo.java +++ b/src/main/java/fi/dy/masa/litematica/render/schematic/ChunkRendererSchematicVbo.java @@ -653,7 +653,19 @@ protected void renderOverlayReducedEdges(BlockPos pos, OverlayType[][][] adjType if (posTmp.getX() == pos.getX() && posTmp.getY() == pos.getY() && posTmp.getZ() == pos.getZ()) { //System.out.printf("plop 2 index: %d, ind: %d, pos: %s, off: %s\n", index, ind, pos, posTmp); - RenderUtils.drawBlockBoxEdgeBatchedLines(this.getChunkRelativePosition(pos), axis, corner, this.overlayColor, bufferOverlayOutlines); + try + { + RenderUtils.drawBlockBoxEdgeBatchedLines(this.getChunkRelativePosition(pos), axis, corner, this.overlayColor, bufferOverlayOutlines); + } + catch (IllegalStateException err) + { + // TODO: This is absolutely awful. Basically some times the render buffer is closed + // while the this processing is happening but if this happens the work the thread was + // doing is going to be thrown away anyway so we just abort & no harm done. Really we + // should be using cancelable futures & coroutines to do this correctly but that is a + // task for not 1:30am when I have work tomorrow. + return; + } lines++; } }