Try fix concurrency issue with render closing

This commit is contained in:
James Seibel
2026-03-14 10:18:40 -05:00
parent 38e104a9fc
commit cd5a3ce52b
2 changed files with 31 additions and 8 deletions
@@ -34,6 +34,7 @@ import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D; import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
import com.seibel.distanthorizons.core.pos.DhSectionPos; import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.render.RenderBufferHandler; import com.seibel.distanthorizons.core.render.RenderBufferHandler;
import com.seibel.distanthorizons.core.render.RenderThreadTaskHandler;
import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer; import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer;
import com.seibel.distanthorizons.core.render.renderer.BeaconRenderHandler; import com.seibel.distanthorizons.core.render.renderer.BeaconRenderHandler;
import com.seibel.distanthorizons.core.render.renderer.IDebugRenderable; import com.seibel.distanthorizons.core.render.renderer.IDebugRenderable;
@@ -371,16 +372,27 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
for (QuadNode<LodRenderSection> node : this.tickNodeHolder.getEnableDeleteChildrenNodes()) for (QuadNode<LodRenderSection> node : this.tickNodeHolder.getEnableDeleteChildrenNodes())
{ {
if (node == null || node.value == null) { continue; } if (node == null
|| node.value == null
node.deleteAllChildren((childRenderSection) -> // only clear the children if there are children to clear
|| node.getDirectChildCount() == 0)
{ {
if (childRenderSection != null) continue;
}
// run this on the render thread to hopefully prevent
// closing render data while rendering is happening
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread("LodQuadTree delayed child cleanup", () ->
{
node.deleteAllChildren((childRenderSection) ->
{ {
childRenderSection.setRenderingEnabled(false); if (childRenderSection != null)
childRenderSection.tryDisableBeacons(); {
childRenderSection.close(); childRenderSection.setRenderingEnabled(false);
} childRenderSection.tryDisableBeacons();
childRenderSection.close();
}
});
}); });
} }
@@ -86,6 +86,17 @@ public class QuadNode<T>
/** @return the number of non-null direct child nodes */
public int getDirectChildCount()
{
int count = 0;
if (this.nwChild != null) { count++; }
if (this.neChild != null) { count++; }
if (this.swChild != null) { count++; }
if (this.seChild != null) { count++; }
return count;
}
/** /**
* Use {@link QuadNode#getNonNullChildCount()} if you want the number of non-null child values. * Use {@link QuadNode#getNonNullChildCount()} if you want the number of non-null child values.
* *