From dbbe1f2d5c04059ee9ddad12a0d33fbaea933683 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 3 Dec 2019 10:41:06 +0000 Subject: [PATCH] Revert "Entity: remove redundant check from spawnTo()" This reverts commit 3028832cd35c53937bb6502f74d3ad53646b12a7. When I created this commit, I made the flawed assumption that spawnTo() would not be used by plugins. In addition, I was not aware that there are some usages of spawnTo() in the core which do not check for chunk usage, such as in Player->showPlayer(). This caused a collection of problems including memory leaks and crashes due to disconnecting players not removing their references from viewed entities. The reverted commit may be the cause of #3178. --- src/pocketmine/entity/Entity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 3eb596d78..a2b3468e9 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -2048,7 +2048,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ * @param Player $player */ public function spawnTo(Player $player) : void{ - if(!isset($this->hasSpawned[$player->getLoaderId()])){ + if(!isset($this->hasSpawned[$player->getLoaderId()]) and $this->chunk !== null and isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])){ $this->hasSpawned[$player->getLoaderId()] = $player; $this->sendSpawnPacket($player);