Fix rare null pointer race condition

This commit is contained in:
James Seibel
2024-12-24 08:12:11 -06:00
parent 0ca2b2f282
commit 248f6db82e
2 changed files with 5 additions and 3 deletions
@@ -84,9 +84,11 @@ public class ColumnRenderBuffer implements AutoCloseable
/** Should be run on a DH thread. */
public synchronized CompletableFuture<ColumnRenderBuffer> makeAndUploadBuffersAsync(LodQuadBuilder builder, EDhApiGpuUploadMethod gpuUploadMethod)
{
if (this.uploadFuture != null)
// separate variable to prevent race condition when checking null
CompletableFuture<ColumnRenderBuffer> future = this.uploadFuture;
if (future != null)
{
return this.uploadFuture;
return future;
}
this.uploadFuture = new CompletableFuture<>();
@@ -73,7 +73,7 @@ public class ColumnRenderBufferBuilder
uploadFuture.whenComplete((uploadedBuffer, exception) ->
{
// clean up if not uploaded
if (!uploadedBuffer.buffersUploaded)
if (uploadedBuffer != null && !uploadedBuffer.buffersUploaded)
{
uploadedBuffer.close();
}