SPIGOT-5228: Entities that are removed during chunk unloads are not

properly removed from the chunk.

This could lead to dead entities accumulating in memory over time if the
chunk never gets fully unloaded (as it is the case for chunks around the
spawn region).

The issue is that Minecraft processes the removal of these entities
during the next tick, when the chunk has already switched to state
INACCESSIBLE and can no longer be retrieved as usual.

For the purpose of removing dead entities from their still loaded but no
longer accessible chunk, this adds and uses a new method with which a
chunk can be accessed without checking its current state first.

By: blablubbabc <lukas@wirsindwir.de>
This commit is contained in:
CraftBukkit/Spigot
2021-02-14 09:24:23 +11:00
parent 98e0c5c715
commit 373ed1ddd5
3 changed files with 38 additions and 17 deletions

View File

@@ -448,6 +448,15 @@
}
}
@@ -909,7 +1070,7 @@
}
private void removeEntityFromChunk(Entity entity) {
- IChunkAccess ichunkaccess = this.getChunkAt(entity.chunkX, entity.chunkZ, ChunkStatus.FULL, false);
+ IChunkAccess ichunkaccess = chunkProvider.getChunkUnchecked(entity.chunkX, entity.chunkZ); // CraftBukkit - SPIGOT-5228: getChunkAt won't find the entity's chunk if it has already been unloaded (i.e. if it switched to state INACCESSIBLE).
if (ichunkaccess instanceof Chunk) {
((Chunk) ichunkaccess).b(entity);
@@ -923,10 +1084,33 @@
this.everyoneSleeping();
}