From 1c5180b7201297f56022b05d3b65f47b311088b8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 2 Mar 2018 18:30:45 +0000 Subject: [PATCH] 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. --- src/pocketmine/level/format/io/region/McRegion.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/level/format/io/region/McRegion.php b/src/pocketmine/level/format/io/region/McRegion.php index 333d13dc8..b83124ede 100644 --- a/src/pocketmine/level/format/io/region/McRegion.php +++ b/src/pocketmine/level/format/io/region/McRegion.php @@ -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; } }