clean up chunk build outputs and renderer resources after job failures #54
No files matched your search
+48
-25
@@ -789,24 +789,45 @@ public abstract class RenderSectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<ChunkJobResult.Success<? extends ChunkTaskOutput>> collectChunkBuildResults() {
|
private ArrayList<ChunkJobResult.Success<? extends ChunkTaskOutput>> 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<ChunkJobResult.Success<? extends ChunkTaskOutput>> drainChunkBuildResults(Queue<ChunkJobResult<? extends ChunkTaskOutput>> buildResults) {
|
||||||
ArrayList<ChunkJobResult.Success<? extends ChunkTaskOutput>> results = new ArrayList<>();
|
ArrayList<ChunkJobResult.Success<? extends ChunkTaskOutput>> results = new ArrayList<>();
|
||||||
|
RuntimeException firstFailure = null;
|
||||||
ChunkJobResult<? extends ChunkTaskOutput> result;
|
ChunkJobResult<? extends ChunkTaskOutput> result;
|
||||||
|
|
||||||
while ((result = this.buildResults.poll()) != null) {
|
while ((result = buildResults.poll()) != null) {
|
||||||
if (result instanceof ChunkJobResult.Success<? extends ChunkTaskOutput> successfulResult) {
|
if (result instanceof ChunkJobResult.Success<? extends ChunkTaskOutput> 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);
|
results.add(successfulResult);
|
||||||
} else if (result instanceof ChunkJobResult.Failure<? extends ChunkTaskOutput> failure) {
|
} else if (result instanceof ChunkJobResult.Failure<? extends ChunkTaskOutput> failure) {
|
||||||
failure.abort();
|
if (firstFailure == null) {
|
||||||
|
firstFailure = failure.asException();
|
||||||
|
} else if (firstFailure != failure.throwable()) {
|
||||||
|
firstFailure.addSuppressed(failure.throwable());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (firstFailure != null) {
|
||||||
|
for (var successfulResult : results) {
|
||||||
|
successfulResult.output().delete();
|
||||||
|
}
|
||||||
|
throw firstFailure;
|
||||||
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -917,25 +938,27 @@ public abstract class RenderSectionManager {
|
|||||||
|
|
||||||
this.builder.shutdown(); // stop all the workers, and cancel any tasks
|
this.builder.shutdown(); // stop all the workers, and cancel any tasks
|
||||||
|
|
||||||
for (var result : this.collectChunkBuildResults()) {
|
try {
|
||||||
result.output().delete(); // delete resources for any pending tasks (including those that were cancelled)
|
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() {
|
public int getTotalSections() {
|
||||||
|
|||||||
+3
-4
@@ -12,12 +12,11 @@ public sealed interface ChunkJobResult<OUTPUT> permits ChunkJobResult.Success, C
|
|||||||
Objects.requireNonNull(throwable);
|
Objects.requireNonNull(throwable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void abort() {
|
public RuntimeException asException() {
|
||||||
if (this.throwable instanceof RuntimeException crashException) {
|
if (this.throwable instanceof RuntimeException crashException) {
|
||||||
// Propagate RuntimeExceptions directly to provide extra information if they are a vanilla crash exception
|
return crashException;
|
||||||
throw crashException;
|
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Exception thrown while executing job", this.throwable);
|
return new RuntimeException("Exception thrown while executing job", this.throwable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user