From a7abd5ff9d7e17a74f69eb082727c67030cffefb Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 27 Nov 2014 13:35:54 +0100 Subject: [PATCH] Catch exceptions when chunks are unloaded --- src/pocketmine/level/Level.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 835bd84c9..b2be7d2e9 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -92,6 +92,7 @@ use pocketmine\tile\Chest; use pocketmine\tile\Tile; use pocketmine\utils\Cache; use pocketmine\utils\LevelException; +use pocketmine\utils\MainLogger; use pocketmine\utils\ReversePriorityQueue; use pocketmine\utils\TextFormat; @@ -1876,12 +1877,20 @@ class Level implements ChunkManager, Metadatable{ } } - if($chunk instanceof FullChunk and $chunk->hasChanged() and $this->getAutoSave()){ - $this->provider->setChunk($x, $z, $chunk); - $this->provider->saveChunk($x, $z); + try{ + if($chunk instanceof FullChunk and $chunk->hasChanged() and $this->getAutoSave()){ + $this->provider->setChunk($x, $z, $chunk); + $this->provider->saveChunk($x, $z); + } + $this->provider->unloadChunk($x, $z, $safe); + }catch (\Exception $e){ + $logger = $this->server->getLogger(); + $logger->error("Error when unloading a chunk: ".$e->getMessage()); + if($logger instanceof MainLogger){ + $logger->logException($e); + } } - $this->provider->unloadChunk($x, $z, $safe); unset($this->chunks[$index]); unset($this->usedChunks[$index]); Cache::remove("world:" . $this->getID() . ":$index");