Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Jun 21, 2024
1 parent 3e00cdd commit ce3bee7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<RenderLayer, BufferBuilderPatch> blockBufferBuilders = new ConcurrentHashMap<>();
private final Map<ChunkRendererSchematicVbo.OverlayRenderType, BufferBuilderPatch> overlayBufferBuilders = new ConcurrentHashMap<>();
private final ConcurrentHashMap<ChunkRendererSchematicVbo.OverlayRenderType, BufferBuilderPatch> overlayBufferBuilders = new ConcurrentHashMap<>();

protected BufferBuilderCache() { }

Expand All @@ -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<BufferBuilderPatch> 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) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
}
Expand Down

0 comments on commit ce3bee7

Please sign in to comment.