From 155eb75b8231bc311596f1205d03038741db7401 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Tue, 24 Jun 2025 00:03:11 +1000 Subject: [PATCH] Attempt fix tracking --- .../common/world/ActiveSectionTracker.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/cortex/voxy/common/world/ActiveSectionTracker.java b/src/main/java/me/cortex/voxy/common/world/ActiveSectionTracker.java index 95f6a8f2..bb690af6 100644 --- a/src/main/java/me/cortex/voxy/common/world/ActiveSectionTracker.java +++ b/src/main/java/me/cortex/voxy/common/world/ActiveSectionTracker.java @@ -196,11 +196,6 @@ public class ActiveSectionTracker { this.engine.saveSection(section); } section.release(false);//Special - } else { - VarHandle.loadLoadFence(); - if (section.isDirty) { - throw new IllegalStateException("Section was dirty but is also unloaded, this is very bad"); - } } } @@ -213,7 +208,19 @@ public class ActiveSectionTracker { final var lock = this.locks[index]; long stamp = lock.writeLock(); { - if (section.trySetFreed()) { + VarHandle.loadLoadFence(); + if (section.isDirty) { + if (section.tryAcquire()) { + if (section.setNotDirty()) {//If the section is dirty we must enqueue for saving + if (this.engine != null) + this.engine.saveSection(section); + } + section.release(false);//Special + } else { + throw new IllegalStateException("Section was dirty but is also unloaded, this is very bad"); + } + } + if (section.getRefCount() == 0 && section.trySetFreed()) { var cached = cache.remove(section.key); var obj = cached.obj; if (obj == null) {