From 8e47a40b4cab9dbec963e16a8ebc65d0a6b867d3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 30 Jan 2019 10:26:18 +0000 Subject: [PATCH 1/2] Level: rename poorly-named parameter of setChunk() this now has a mouthful of a name. I'd like to invert it, but I can't do that without silently breaking backwards compatibility, which is unacceptable. --- src/pocketmine/level/Level.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index d04ce5e75..ebd461d6a 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -2475,9 +2475,9 @@ class Level implements ChunkManager, Metadatable{ * @param int $chunkX * @param int $chunkZ * @param Chunk|null $chunk - * @param bool $unload + * @param bool $deleteEntitiesAndTiles Whether to delete entities and tiles on the old chunk, or transfer them to the new one */ - public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk = null, bool $unload = true){ + public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk = null, bool $deleteEntitiesAndTiles = true){ if($chunk === null){ return; } @@ -2488,7 +2488,7 @@ class Level implements ChunkManager, Metadatable{ $chunkHash = Level::chunkHash($chunkX, $chunkZ); $oldChunk = $this->getChunk($chunkX, $chunkZ, false); if($oldChunk !== null and $oldChunk !== $chunk){ - if($unload){ + if($deleteEntitiesAndTiles){ $this->unloadChunk($chunkX, $chunkZ, false, false); }else{ foreach($oldChunk->getEntities() as $entity){ From eebd90ec4245abbcdddfc11fe3f4dc36a008f19e Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 30 Jan 2019 10:58:35 +0000 Subject: [PATCH 2/2] Level: fixed setChunk() leaking memory when not copying tiles/entities closes #2719 --- src/pocketmine/level/Level.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index ebd461d6a..69144cde5 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -2489,6 +2489,13 @@ class Level implements ChunkManager, Metadatable{ $oldChunk = $this->getChunk($chunkX, $chunkZ, false); if($oldChunk !== null and $oldChunk !== $chunk){ if($deleteEntitiesAndTiles){ + $players = $this->getChunkPlayers($chunkX, $chunkZ); + foreach($players as $player){ + $chunk->addEntity($player); + $oldChunk->removeEntity($player); + $player->chunk = $chunk; + } + //TODO: this causes chunkloaders to receive false "unloaded" notifications $this->unloadChunk($chunkX, $chunkZ, false, false); }else{ foreach($oldChunk->getEntities() as $entity){