limit queued render section loading to fix memory ballooning

This commit is contained in:
James Seibel
2025-01-04 09:02:29 -06:00
parent 184f261d6b
commit cc006ebb5d
2 changed files with 13 additions and 16 deletions
@@ -47,10 +47,7 @@ import org.jetbrains.annotations.Nullable;
import javax.annotation.WillNotClose;
import java.awt.*;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
import java.util.function.Supplier;
/**
@@ -141,6 +138,13 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
return;
}
// don't queue up an infinite number of tasks
// doing so will cause memory use to balloon when swapping between dimensions
if (executor.getQueue().size() > executor.getPoolSize())
{
return;
}
try
{
this.getAndBuildRenderDataFuture = CompletableFuture.runAsync(() ->
@@ -423,6 +427,10 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
// cancel all in-progress futures since they aren't needed any more
if (this.getAndBuildRenderDataFuture != null)
{
// Note to self:
// canceling a task prevents it from running, but doesn't allow
// us to purge it from the executor it was queued in.
// As far as James can tell this appears to be a Java bug.
this.getAndBuildRenderDataFuture.cancel(true);
}
if (this.bufferUploadFuture != null)
@@ -451,18 +451,7 @@ public class RenderBufferHandler implements AutoCloseable
//=========//
@Override
public void close()
{
Iterator<QuadNode<LodRenderSection>> nodeIterator = this.lodQuadTree.nodeIterator();
while (nodeIterator.hasNext())
{
LodRenderSection renderSection = nodeIterator.next().value;
if (renderSection != null)
{
renderSection.close();
}
}
}
public void close() { this.lodQuadTree.close(); }