From 9da6f8984c72d03c79f573f4640e584a94e0598a Mon Sep 17 00:00:00 2001 From: rdh Date: Mon, 23 Nov 2026 00:21:09 -0500 Subject: [PATCH] clean up chunk build outputs and renderer resources after job failures --- .../render/chunk/RenderSectionManager.java | 73 ++++++++++++------- .../compile/executor/ChunkJobResult.java | 7 +- 2 files changed, 51 insertions(+), 29 deletions(-) diff --git a/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/RenderSectionManager.java b/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/RenderSectionManager.java index 9fd18ccb6..93d6c60a1 100644 --- a/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/RenderSectionManager.java +++ b/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/RenderSectionManager.java @@ -789,24 +789,45 @@ public abstract class RenderSectionManager { } private ArrayList> collectChunkBuildResults() { + var results = drainChunkBuildResults(this.buildResults); + + for (var successfulResult : results) { + this.jobMetricsTracker.collectMetrics(successfulResult); + + if (successfulResult.output() instanceof ChunkSortOutput sort && sort.render.isTreeSorted() && successfulResult.executionTimeNanos() >= 0) { + this.treeSortMetrics.collect(successfulResult.executionTimeNanos()); + } + } + + return results; + } + + static ArrayList> drainChunkBuildResults(Queue> buildResults) { ArrayList> results = new ArrayList<>(); + RuntimeException firstFailure = null; ChunkJobResult result; - while ((result = this.buildResults.poll()) != null) { + while ((result = buildResults.poll()) != null) { if (result instanceof ChunkJobResult.Success successfulResult) { - this.jobMetricsTracker.collectMetrics(successfulResult); - - if (successfulResult.output() instanceof ChunkSortOutput sort && sort.render.isTreeSorted() && successfulResult.executionTimeNanos() >= 0) { - this.treeSortMetrics.collect(successfulResult.executionTimeNanos()); - } results.add(successfulResult); } else if (result instanceof ChunkJobResult.Failure failure) { - failure.abort(); + if (firstFailure == null) { + firstFailure = failure.asException(); + } else if (firstFailure != failure.throwable()) { + firstFailure.addSuppressed(failure.throwable()); + } } else { throw new AssertionError(); } } + if (firstFailure != null) { + for (var successfulResult : results) { + successfulResult.output().delete(); + } + throw firstFailure; + } + return results; } @@ -917,25 +938,27 @@ public abstract class RenderSectionManager { this.builder.shutdown(); // stop all the workers, and cancel any tasks - for (var result : this.collectChunkBuildResults()) { - result.output().delete(); // delete resources for any pending tasks (including those that were cancelled) + try { + for (var result : this.collectChunkBuildResults()) { + result.output().delete(); // delete resources for any pending tasks (including those that were cancelled) + } + } finally { + this.renderListManager.destroy(); + if (this.shadowRenderListManager != null) { + this.shadowRenderListManager.destroy(); + } + this.sectionGraph.destroy(); + + try (CommandList commandList = RenderDevice.INSTANCE.createCommandList()) { + this.regions.delete(commandList); + this.chunkRenderer.delete(commandList); + } + + this.renderPassDrawTimers.values().forEach(TimerQueryManager::close); + this.renderPassDrawTimers.clear(); + + this.sectionsWithGlobalEntities.clear(); } - - this.renderListManager.destroy(); - if (this.shadowRenderListManager != null) { - this.shadowRenderListManager.destroy(); - } - this.sectionGraph.destroy(); - - try (CommandList commandList = RenderDevice.INSTANCE.createCommandList()) { - this.regions.delete(commandList); - this.chunkRenderer.delete(commandList); - } - - this.renderPassDrawTimers.values().forEach(TimerQueryManager::close); - this.renderPassDrawTimers.clear(); - - this.sectionsWithGlobalEntities.clear(); } public int getTotalSections() { diff --git a/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/executor/ChunkJobResult.java b/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/executor/ChunkJobResult.java index ed1a89beb..9dd612d39 100644 --- a/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/executor/ChunkJobResult.java +++ b/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/executor/ChunkJobResult.java @@ -12,12 +12,11 @@ public sealed interface ChunkJobResult permits ChunkJobResult.Success, C Objects.requireNonNull(throwable); } - public void abort() { + public RuntimeException asException() { if (this.throwable instanceof RuntimeException crashException) { - // Propagate RuntimeExceptions directly to provide extra information if they are a vanilla crash exception - throw crashException; + return crashException; } else { - throw new RuntimeException("Exception thrown while executing job", this.throwable); + return new RuntimeException("Exception thrown while executing job", this.throwable); } } } -- 2.54.1