Skip to content

Commit

Permalink
Uses alternative way to process holders to prevent CMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Jul 23, 2022
1 parent b03379b commit 1f26bab
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 39 deletions.

This file was deleted.

Expand Up @@ -7,6 +7,7 @@
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.LongSet;
import it.unimi.dsi.fastutil.objects.ObjectArrayFIFOQueue;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
import net.minecraft.server.world.ChunkHolder;
import net.minecraft.server.world.ChunkTaskPrioritySystem;
Expand Down Expand Up @@ -65,7 +66,7 @@ protected static int getLevel(SortedArraySet<ChunkTicket<?>> sortedArraySet) {
protected io.papermc.paper.util.misc.Delayed8WayDistancePropagator2D ticketLevelPropagator;

@Unique
private ArrayList<ChunkHolder> pendingChunkHolderUpdates;
private ObjectArrayFIFOQueue<ChunkHolder> pendingChunkHolderUpdates;

// Paper distance map propagates level from max to 0 while vanilla
// one propagate from 0 to max
Expand Down Expand Up @@ -103,7 +104,7 @@ protected void rehash(int newN) {
this.ticketLevelUpdates.putAndMoveToLast(coordinate, convertBetweenTicketLevels(newLevel));
}
);
this.pendingChunkHolderUpdates = new ArrayList<>();
this.pendingChunkHolderUpdates = new ObjectArrayFIFOQueue<>();
}

@Redirect(method = {"purge", "addTicket(JLnet/minecraft/server/world/ChunkTicket;)V", "removeTicket(JLnet/minecraft/server/world/ChunkTicket;)V", "removePersistentTickets"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ChunkTicketManager$TicketDistanceLevelPropagator;updateLevel(JIZ)V"), require = 3, expect = 3)
Expand Down Expand Up @@ -160,13 +161,12 @@ public int tickTickets(ChunkTicketManager.TicketDistanceLevelPropagator __, int
continue;
}

this.pendingChunkHolderUpdates.add(holder);
this.pendingChunkHolderUpdates.enqueue(holder);
}

for (ChunkHolder holder : this.pendingChunkHolderUpdates) {
((IChunkHolder) holder).invokeTick1(threadedAnvilChunkStorage, this.mainThreadExecutor);
while (!this.pendingChunkHolderUpdates.isEmpty()) {
((IChunkHolder) this.pendingChunkHolderUpdates.dequeue()).invokeTick1(threadedAnvilChunkStorage, this.mainThreadExecutor);
}
this.pendingChunkHolderUpdates.clear();

return hasUpdates ? distance - 1 : distance;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/vmp.mixins.json
Expand Up @@ -25,7 +25,6 @@
"chunkloading.commands.MixinSpreadPlayersCommand",
"chunkloading.commands.MixinTeleportCommand",
"chunkloading.portals.MixinEntity",
"chunkloading.portals.MixinServerPlayerEntity",
"chunksending.MixinThreadedAnvilChunkStorage",
"chunksending.c2me_notickvd_compat.MixinNoTickChunkSendingInterceptor",
"entity.item.MixinEntity",
Expand Down

0 comments on commit 1f26bab

Please sign in to comment.