Skip to content

Commit 19b5da1

Browse files
committed
fix: account for chunksBeingSavedCount in gc free serializer
1 parent 49bc6b9 commit 19b5da1

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

c2me-rewrites-chunk-serializer/src/main/java/com/ishland/c2me/rewrites/chunk_serializer/mixin/MixinThreadedAnvilChunkStorage.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import java.nio.file.Path;
3232
import java.util.concurrent.CompletableFuture;
33+
import java.util.concurrent.atomic.AtomicInteger;
3334
import java.util.function.Function;
3435

3536
@Mixin(value = ServerChunkLoadingManager.class, priority = 1099)
@@ -59,6 +60,8 @@ public MixinThreadedAnvilChunkStorage(StorageKey arg, Path path, DataFixer dataF
5960

6061
@Shadow protected abstract @Nullable ChunkHolder getCurrentChunkHolder(long pos);
6162

63+
@Shadow @Final private AtomicInteger chunksBeingSavedCount;
64+
6265
/**
6366
* @author Kroppeb
6467
* @reason Reduces allocations
@@ -87,9 +90,10 @@ private boolean save(Chunk chunk) {
8790

8891
Profilers.get().visit("chunkSave");
8992

93+
this.chunksBeingSavedCount.incrementAndGet();
94+
SerializedChunk chunkSerializer = SerializedChunk.fromChunk(this.world, chunk);
9095
//region start replaced code
9196
// NbtCompound nbtCompound = ChunkSerializer.serialize(this.world, chunk);
92-
SerializedChunk chunkSerializer = SerializedChunk.fromChunk(this.world, chunk);
9397
CompletableFuture<Void> saveFuture = CompletableFuture.supplyAsync(() -> {
9498
NbtWriter nbtWriter = new NbtWriter();
9599
nbtWriter.start(NbtElement.COMPOUND_TYPE);
@@ -102,6 +106,15 @@ private boolean save(Chunk chunk) {
102106
return future;
103107
}, ((IVanillaChunkManager) this).c2me$getSchedulingManager().positionedExecutor(chunk.getPos().toLong())).thenCompose(Function.identity());
104108

109+
saveFuture.handle((void_, exceptionx) -> {
110+
if (exceptionx != null) {
111+
this.world.getServer().onChunkSaveFailure(exceptionx, this.getStorageKey(), chunkPos);
112+
}
113+
114+
this.chunksBeingSavedCount.decrementAndGet();
115+
return null;
116+
});
117+
105118
ChunkHolder holder = this.getCurrentChunkHolder(chunk.getPos().toLong());
106119
if (holder != null) {
107120
((IChunkHolder) holder).invokeCombineSavingFuture(saveFuture);

0 commit comments

Comments
 (0)