mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
McRegion: don't assign regions to the index until all exception handling is done
it appears that errors are occurring in the exception handler when handling corrupted regions, leaving regions in the provider index with incomplete location tables. This causes strange-looking errors later down the line. This moves the region assignment to the end of the condition to avoid leaving incomplete/corrupted regions in the location table when errors occur.
This commit is contained in:
parent
fa6d44ea9e
commit
1c5180b720
@ -320,22 +320,25 @@ class McRegion extends BaseLevelProvider{
|
||||
protected function loadRegion(int $regionX, int $regionZ){
|
||||
if(!isset($this->regions[$index = Level::chunkHash($regionX, $regionZ)])){
|
||||
$path = $this->pathToRegion($regionX, $regionZ);
|
||||
$this->regions[$index] = new RegionLoader($path, $regionX, $regionZ);
|
||||
|
||||
$region = new RegionLoader($path, $regionX, $regionZ);
|
||||
try{
|
||||
$this->regions[$index]->open();
|
||||
$region->open();
|
||||
}catch(CorruptedRegionException $e){
|
||||
$logger = MainLogger::getLogger();
|
||||
$logger->error("Corrupted region file detected: " . $e->getMessage());
|
||||
|
||||
$this->regions[$index]->close(false); //Do not write anything to the file
|
||||
$region->close(false); //Do not write anything to the file
|
||||
|
||||
$backupPath = $path . ".bak." . time();
|
||||
rename($path, $backupPath);
|
||||
$logger->error("Corrupted region file has been backed up to " . $backupPath);
|
||||
|
||||
$this->regions[$index] = new RegionLoader($path, $regionX, $regionZ);
|
||||
$this->regions[$index]->open(); //this will create a new empty region to replace the corrupted one
|
||||
$region = new RegionLoader($path, $regionX, $regionZ);
|
||||
$region->open(); //this will create a new empty region to replace the corrupted one
|
||||
}
|
||||
|
||||
$this->regions[$index] = $region;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user