Merge pull request #2771 from alejandroliu/ChunkCorruption

Fix some Chunk corruption due to Chunk overlap
This commit is contained in:
Shoghi Cervantes 2015-03-13 09:24:24 +01:00
commit be20f61a93

View File

@ -189,8 +189,8 @@ class RegionLoader{
$sectors = (int) ceil(($length + 4) / 4096); $sectors = (int) ceil(($length + 4) / 4096);
$index = self::getChunkOffset($x, $z); $index = self::getChunkOffset($x, $z);
if($this->locationTable[$index][1] < $sectors){ if($this->locationTable[$index][1] < $sectors){
$this->locationTable[$index][0] = $this->lastSector+1;
$this->lastSector += $sectors; //The GC will clean this shift "later" $this->lastSector += $sectors; //The GC will clean this shift "later"
$this->locationTable[$index][0] = $this->lastSector;
} }
$this->locationTable[$index][1] = $sectors; $this->locationTable[$index][1] = $sectors;
$this->locationTable[$index][2] = time(); $this->locationTable[$index][2] = time();
@ -247,7 +247,8 @@ class RegionLoader{
$chunk = Binary::writeInt(strlen($chunk)) . $chunk; $chunk = Binary::writeInt(strlen($chunk)) . $chunk;
$sectors = (int) ceil(strlen($chunk) / 4096); $sectors = (int) ceil(strlen($chunk) / 4096);
if($sectors > $this->locationTable[$i][1]){ if($sectors > $this->locationTable[$i][1]){
$this->locationTable[$i][0] = $this->lastSector += $sectors; $this->locationTable[$i][0] = $this->lastSector + 1;
$this->lastSector += $sectors;
} }
fseek($this->filePointer, $this->locationTable[$i][0] << 12); fseek($this->filePointer, $this->locationTable[$i][0] << 12);
fwrite($this->filePointer, str_pad($chunk, $sectors << 12, "\x00", STR_PAD_RIGHT)); fwrite($this->filePointer, str_pad($chunk, $sectors << 12, "\x00", STR_PAD_RIGHT));