Clear the debug wireframes after leaving the current world.

This commit is contained in:
James Seibel
2023-09-07 20:20:11 -05:00
parent 36fc6aaea3
commit ea7f199c9b
2 changed files with 13 additions and 8 deletions
@@ -25,6 +25,7 @@ import com.seibel.distanthorizons.core.dataObjects.transformers.ChunkToLodBuilde
import com.seibel.distanthorizons.core.dataObjects.transformers.FullDataToRenderDataTransformer;
import com.seibel.distanthorizons.core.file.fullDatafile.FullDataFileHandler;
import com.seibel.distanthorizons.core.generation.WorldGenerationQueue;
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
import com.seibel.distanthorizons.core.world.*;
/** Contains code and variables used by both {@link ClientApi} and {@link ServerApi} */
@@ -67,6 +68,8 @@ public class SharedApi
WorldGenerationQueue.shutdownWorldGenThreadPool();
ChunkToLodBuilder.shutdownExecutorService();
DebugRenderer.clearRenderables();
// recommend that the garbage collector cleans up any objects from the old world
System.gc();
}
@@ -264,26 +264,28 @@ public class DebugRenderer
private void removeRenderer(IDebugRenderable r)
{
synchronized (renderers)
synchronized (this.renderers)
{
Iterator<WeakReference<IDebugRenderable>> it = renderers.iterator();
while (it.hasNext())
Iterator<WeakReference<IDebugRenderable>> iterator = this.renderers.iterator();
while (iterator.hasNext())
{
WeakReference<IDebugRenderable> ref = it.next();
if (ref.get() == null)
WeakReference<IDebugRenderable> renderableRef = iterator.next();
if (renderableRef.get() == null)
{
it.remove();
iterator.remove();
continue;
}
if (ref.get() == r)
if (renderableRef.get() == r)
{
it.remove();
iterator.remove();
return;
}
}
}
}
public static void clearRenderables() { INSTANCE.renderers.clear(); }
public void init()
{
if (init) return;