Don't tick chunks or entities on chunks that are queued for unload.

Treat chunks in the unload queue as if they are already unloaded to prevent
processing on them removing them from the unload queue and leaking.
This commit is contained in:
Travis Watkins 2012-08-04 02:22:57 -05:00
parent fdd01feb8c
commit e5acb6cf3a
2 changed files with 30 additions and 3 deletions

View File

@ -23,7 +23,7 @@ public class ChunkProviderServer implements IChunkProvider {
public Chunk emptyChunk;
public IChunkProvider chunkProvider; // CraftBukkit
private IChunkLoader e;
public boolean forceChunkLoad = false; // true -> false
public boolean forceChunkLoad = true;
public LongHashtable<Chunk> chunks = new LongHashtable<Chunk>();
public List chunkList = new ArrayList();
public WorldServer world;
@ -37,7 +37,7 @@ public class ChunkProviderServer implements IChunkProvider {
}
public boolean isChunkLoaded(int i, int j) {
return this.chunks.containsKey(i, j); // CraftBukkit
return !this.unloadQueue.containsKey(i, j) && this.chunks.containsKey(i, j); // CraftBukkit
}
public void queueUnload(int i, int j) {

View File

@ -1053,7 +1053,12 @@ public abstract class World implements IBlockAccess {
for (i = 0; i < this.j.size(); ++i) {
entity = (Entity) this.j.get(i);
// CraftBukkit start - fixed an NPE
// CraftBukkit start - fixed an NPE, don't process entities in chunks queued for unload
ChunkProviderServer chunkProviderServer = ((WorldServer) entity.world).chunkProviderServer;
if (chunkProviderServer.unloadQueue.containsKey(MathHelper.floor(entity.locX) >> 4, MathHelper.floor(entity.locZ) >> 4)) {
continue;
}
if (entity == null) {
continue;
}
@ -1092,6 +1097,14 @@ public abstract class World implements IBlockAccess {
for (i = 0; i < this.entityList.size(); ++i) {
entity = (Entity) this.entityList.get(i);
// CraftBukkit start - don't tick entities in chunks queued for unload
ChunkProviderServer chunkProviderServer = ((WorldServer) entity.world).chunkProviderServer;
if (chunkProviderServer.unloadQueue.containsKey(MathHelper.floor(entity.locX) >> 4, MathHelper.floor(entity.locZ) >> 4)) {
continue;
}
// CraftBukkit end
if (entity.vehicle != null) {
if (!entity.vehicle.dead && entity.vehicle.passenger == entity) {
continue;
@ -1129,6 +1142,13 @@ public abstract class World implements IBlockAccess {
while (iterator.hasNext()) {
TileEntity tileentity = (TileEntity) iterator.next();
// CraftBukkit start - don't tick entities in chunks queued for unload
ChunkProviderServer chunkProviderServer = ((WorldServer) tileentity.world).chunkProviderServer;
if (chunkProviderServer.unloadQueue.containsKey(tileentity.x >> 4, tileentity.z >> 4)) {
continue;
}
// CraftBukkit end
if (!tileentity.p() && tileentity.m() && this.isLoaded(tileentity.x, tileentity.y, tileentity.z)) {
tileentity.g();
}
@ -1791,6 +1811,13 @@ public abstract class World implements IBlockAccess {
for (int l = -b0; l <= b0; ++l) {
for (int i1 = -b0; i1 <= b0; ++i1) {
// CraftBukkit start - don't tick chunks queued for unload
ChunkProviderServer chunkProviderServer = ((WorldServer) entityhuman.world).chunkProviderServer;
if (chunkProviderServer.unloadQueue.containsKey(l + j, i1 + k)) {
continue;
}
// CraftBukkit end
this.chunkTickList.add(org.bukkit.craftbukkit.util.LongHash.toLong(l + j, i1 + k)); // CraftBukkit
}
}