mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Possible fix for 'Invalid Chunk given' crash
This commit is contained in:
parent
06c01f14c6
commit
4d7c953572
@ -55,7 +55,7 @@ class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{
|
||||
}
|
||||
}
|
||||
|
||||
public function readChunk($x, $z, $generate = true){
|
||||
public function readChunk($x, $z, $generate = true, $forward = false){
|
||||
$index = self::getChunkOffset($x, $z);
|
||||
if($index < 0 or $index >= 4096){
|
||||
//Regenerate chunk due to corruption
|
||||
@ -97,8 +97,15 @@ class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{
|
||||
}
|
||||
|
||||
$chunk = Chunk::fromBinary(fread($this->filePointer, $length - 1), $this->levelProvider);
|
||||
|
||||
return $chunk instanceof Chunk ? $chunk : false;
|
||||
if($chunk instanceof Chunk){
|
||||
return $chunk;
|
||||
}elseif($forward === false){
|
||||
trigger_error("Corrupted chunk detected", E_USER_WARNING);
|
||||
$this->generateChunk($x, $z);
|
||||
return $this->readChunk($x, $z, $generate, true);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function generateChunk($x, $z){
|
||||
|
@ -79,7 +79,7 @@ class RegionLoader{
|
||||
return !($this->locationTable[$index][0] === 0 or $this->locationTable[$index][1] === 0);
|
||||
}
|
||||
|
||||
public function readChunk($x, $z, $generate = true){
|
||||
public function readChunk($x, $z, $generate = true, $forward = false){
|
||||
$index = self::getChunkOffset($x, $z);
|
||||
if($index < 0 or $index >= 4096){
|
||||
//Regenerate chunk due to corruption
|
||||
@ -121,8 +121,15 @@ class RegionLoader{
|
||||
}
|
||||
|
||||
$chunk = Chunk::fromBinary(fread($this->filePointer, $length - 1), $this->levelProvider);
|
||||
|
||||
return $chunk instanceof Chunk ? $chunk : false;
|
||||
if($chunk instanceof Chunk){
|
||||
return $chunk;
|
||||
}elseif($forward === false){
|
||||
trigger_error("Corrupted chunk detected", E_USER_WARNING);
|
||||
$this->generateChunk($x, $z);
|
||||
return $this->readChunk($x, $z, $generate, true);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function chunkExists($x, $z){
|
||||
|
Loading…
x
Reference in New Issue
Block a user