Fixed crash on tile unloading

This commit is contained in:
Shoghi Cervantes
2014-08-15 16:37:39 +02:00
parent a7b44e3892
commit ec93ed3e3d
2 changed files with 10 additions and 3 deletions

View File

@ -1048,7 +1048,9 @@ abstract class Entity extends Position implements Metadatable{
if($this->chunk instanceof FullChunk){ if($this->chunk instanceof FullChunk){
$this->chunk->removeEntity($this); $this->chunk->removeEntity($this);
} }
$this->getLevel()->removeEntity($this); if(($level = $this->getLevel()) instanceof Level){
$level->removeEntity($this);
}
$this->despawnFromAll(); $this->despawnFromAll();
$this->level->release(); $this->level->release();
} }

View File

@ -29,6 +29,7 @@ use pocketmine\event\Timings;
use pocketmine\level\format\Chunk; use pocketmine\level\format\Chunk;
use pocketmine\level\format\FullChunk; use pocketmine\level\format\FullChunk;
use pocketmine\level\format\LevelProvider; use pocketmine\level\format\LevelProvider;
use pocketmine\level\Level;
use pocketmine\level\Position; use pocketmine\level\Position;
use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Compound;
@ -111,8 +112,12 @@ abstract class Tile extends Position{
if($this->closed === false){ if($this->closed === false){
$this->closed = true; $this->closed = true;
unset(Tile::$needUpdate[$this->id]); unset(Tile::$needUpdate[$this->id]);
$this->getLevel()->removeTile($this); if($this->chunk instanceof FullChunk){
$this->chunk->removeTile($this); $this->chunk->removeTile($this);
}
if(($level = $this->getLevel()) instanceof Level){
$level->removeTile($this);
}
$this->level->release(); $this->level->release();
} }
} }