For some reason when I run an asynctask and inside that, perform a call back, I get a segmentation fault. Here is the main class code: PHP: $sender->sendMessage("§4§lLoading Stats§8...");$this->getServer()->getScheduler()->scheduleAsyncTask(new showPlayerData($this->plugin, serialize($sender), $sender->getName())); I also tried without serialising the sender var. showPlayerData.php PHP: <?php#### SamCraft SkyWars - Core Plugin | LB Task ###namespace Samueljh1\Samcraft\SkyWars\LeaderboardSystem;use pocketmine\plugin\Plugin;use pocketmine\scheduler\ServerScheduler;use pocketmine\scheduler\AsyncTask;use pocketmine\scheduler\PluginTask;use pocketmine\Server;class showPlayerData extends AsyncTask{ public $plugin, $sender, $name; public function __construct($plugin, $sender, $name){ $this->plugin = $plugin; $this->sender = $sender; $this->name = $name; } public function onRun(){ $this->data = explode(",", file_get_contents("http://skywars.samueljh1.net/LeaderboardRequest.php?usr=" . $this->name)); } public function onCompletion(Server $server){ $this->plugin->sendStatsMessage($this->sender, $this->data, $this->name); }} And the sendStatsMessage() function: PHP: public function sendStatsMessage($sender, $data, $name){ $sender = unserialize($sender); if($data[0] !== "Error") { $this->setPlayerData($data); if (isset($data[5])) { $pname = $data[0]; $score = $data[1]; $kills = $data[2]; $deaths = $data[3]; $rank = str_replace("Plus", "+", $data[5]); $this->showStatMessage($sender, $pname, $score, $kills, $deaths, $rank); } else { $this->showStatMessage($sender, $data[0], 0, 0, 0, "Member"); } } else{ $sender->sendMessage("§8§l\"§6" . $name . "§8\" §4is not a Player!"); }} Everything works, the message sends with the correct data - but the segmentation fault occurs after the sendStatsMessage() function finishes. Any Ideas?
My experience have been that serializing $sender (specially if it is a Player) is problematic. The way I got around it is (again assuming it is player), is I only pass $sender->getName() to AsyncTask. Then to get the Sender later from the onCompletion, I do $sender = $server->getPlayer($sender_name). Make sure you check for null returns. It is probably good to do this anyway because the Player could have logged out by the time the AsyncTask finishes.
Oh yea forgot about task ending and player quitting xD Also @Kvetinac97 i have already made the plugin xD (sw.samueljh1.net:19133)
This is because the Player is connected to the Server object, for example $player->getLevel()->getServer(), and serializing the entire server will eat your memory very quickly.