From 1e7f9214cc2025ad1c12a9967200a35b63155e5d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 3 Dec 2020 18:36:54 +0000 Subject: [PATCH] Entity: flag for despawn if entering ungenerated terrain previously this created an empty chunk for the entity to hang around in until the terrain was generated, but that's problematic for several reasons, most importantly the fact that non-generated chunks are not saved. --- src/entity/Entity.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 2af2883f7..75e750202 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1366,7 +1366,16 @@ abstract class Entity{ if($this->chunk !== null){ $this->chunk->removeEntity($this); } - $this->chunk = $this->getWorld()->loadChunk($chunkX, $chunkZ, true); + $this->chunk = $this->getWorld()->loadChunk($chunkX, $chunkZ, false); + if($this->chunk === null){ + //TODO: this is a non-ideal solution for a hard problem + //when this happens the entity won't be tracked by any chunk, so we can't have it hanging around in memory + //we also can't allow this to cause chunk generation, nor can we just create an empty ungenerated chunk + //for it, because an empty chunk won't get saved, so the entity will vanish anyway. Therefore, this is + //the cleanest way to make sure this doesn't result in leaks. + $this->getWorld()->getLogger()->debug("Entity $this->id is in ungenerated terrain, flagging for despawn"); + $this->flagForDespawn(); + } $this->chunkX = $chunkX; $this->chunkZ = $chunkZ;