Guys, i wanna load images in maps Asynchronously but core only dumped PHP: class AsyncUpdate extends AsyncTask{ private $player; private $mapId; private $color; private $pk; function __construct(Player $player, int $mapId, $color){ $this->player = $player; $this->mapId = $mapId; $this->color = $color; } function onRun( ){ $this->pk = new ClientboundMapItemDataPacket(); $this->pk->mapId = $this->mapId; $this->pk->scale = 0; $this->pk->width = 128; $this->pk->height = 128; $this->pk->colors = $this->color; } function onCompletion(Server $server){ //$this->player->dataPacket($this->pk); - Segmentation fault (core dumped) //$server->broadcastPacket([$this->player],$this->pk); - Segmentation fault (core dumped) unset($this->pk); unset($this->player); unset($this->mapId); unset($this->color); }}//func in main public function sendMap(Player $player, int $mapId, $color) { $this->getServer()->getScheduler()->scheduleAsyncTask(new AsyncUpdate($player, $mapId, $color)); }
PHP: /** * @param $player string */function __construct(string $player, int $mapId, $color){ $this->player = $player; $this->mapId = $mapId; $this->color = $color;}public function onRun( ) { $pk = new ClientboundMapItemDataPacket(); $pk->mapId = $this->mapId; $pk->scale = 0; $pk->width = 128; $pk->height = 128; $pk->colors = $this->color; $this->setResult($pk);}public function onCompletion(Server $server) { if(($player = $server->getPlayer($this->player))) { $player->dataPacket($this->getResult()); }} Don't pass objects through threads. Except ones that can be serialized
Code: Error: pthreads detected an attempt to connect to an object which has already been destroyed File: /src/pocketmine/scheduler/AsyncTask Line: 85 Type: notice Code: [76] [77] public function isCrashed(){ [78] return $this->crashed; [79] } [80] [81] /** [82] * @return mixed [83] */ [84] public function getResult(){ [85] return $this->serialized ? unserialize($this->result) : $this->result; [86] }
Oh yeah, didn't notice. By doing Player::dataPacket($this->getResult()) the packet (object) is passed through threads. Easiest way to resolve this is to, break packet data into primitives and build the packet back together in the main thread.
Pass all object properties individually to main thread PHP: $server->getPluginManager()->getPlugin("MyPlugin")->constructAndSendMapPacket( $pk->scale, $pk->width, $pk->height, $pk->colors, $pk->mapId, $this->playerName);
The whole task is worthless. The laggy part either comes from encoding data for sending, or in the process of sending. You are only setting fields in the task, which does not give any improvement at all.