diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index fb785553d..cf251a43b 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -2440,13 +2440,8 @@ class Level implements ChunkManager, Metadatable{ Level::getXZ($index, $x, $z); if(isset($this->chunkSendTasks[$index])){ - if($this->chunkSendTasks[$index]->isCrashed()){ - unset($this->chunkSendTasks[$index]); - $this->server->getLogger()->error("Failed to prepare chunk $x $z for sending, retrying"); - }else{ - //Not ready for sending yet - continue; - } + //Not ready for sending yet + continue; } if(isset($this->chunkCache[$index])){ @@ -2485,7 +2480,12 @@ class Level implements ChunkManager, Metadatable{ $this->server->getLogger()->debug("Dropped prepared chunk $x $z due to world not loaded"); } }); - $this->server->getAsyncPool()->submitTask($task = new ChunkRequestTask($x, $z, $chunk, $promise)); + $this->server->getAsyncPool()->submitTask($task = new ChunkRequestTask($x, $z, $chunk, $promise, function() use($index, $x, $z){ + if(isset($this->chunkSendTasks[$index])){ + unset($this->chunkSendTasks[$index]); + $this->server->getLogger()->error("Failed to prepare chunk $x $z for sending, retrying"); + } + })); $this->chunkSendTasks[$index] = $task; $this->timings->syncChunkSendPrepareTimer->stopTiming(); diff --git a/src/pocketmine/network/mcpe/ChunkRequestTask.php b/src/pocketmine/network/mcpe/ChunkRequestTask.php index 4053dd6c5..11bf7ae58 100644 --- a/src/pocketmine/network/mcpe/ChunkRequestTask.php +++ b/src/pocketmine/network/mcpe/ChunkRequestTask.php @@ -37,14 +37,14 @@ class ChunkRequestTask extends AsyncTask{ protected $compressionLevel; - public function __construct(int $chunkX, int $chunkZ, Chunk $chunk, CompressBatchPromise $promise){ + public function __construct(int $chunkX, int $chunkZ, Chunk $chunk, CompressBatchPromise $promise, ?\Closure $onError = null){ $this->compressionLevel = NetworkCompression::$LEVEL; $this->chunk = $chunk->networkSerialize(); $this->chunkX = $chunkX; $this->chunkZ = $chunkZ; - $this->storeLocal($promise); + $this->storeLocal(["promise" => $promise, "errorHook" => $onError]); } public function onRun() : void{ @@ -59,9 +59,14 @@ class ChunkRequestTask extends AsyncTask{ $this->setResult(NetworkCompression::compress($stream->getBuffer(), $this->compressionLevel)); } + public function onError() : void{ + $hook = $this->fetchLocal()["errorHook"]; + $hook(); + } + public function onCompletion() : void{ /** @var CompressBatchPromise $promise */ - $promise = $this->fetchLocal(); + $promise = $this->fetchLocal()["promise"]; $promise->resolve($this->getResult()); } }