After much research, I found the source of a problem that happens to me by reproducing it at will.
It seems that there is a strange behavior with the modification of a static variable, through a callable in another thread than the one that created this callable.
The example code will speak better than my explanations which can be shaky
Reproducing Code
A class :
class AsyncEvilTask extends AsyncTask {
private $onRun;
private $onCompletion;
public function __construct(callable $onRun, callable $onCompletion) {
$this->onRun = $onRun;
$this->onCompletion = $onCompletion;
}
public function onRun() : void {
$callable = $this->onRun;
$callable($this);
}
public function onCompletion(): void {
$callable = $this->onCompletion;
$callable($this);
}
}
In a PocketMine-MP plugin class:
class Main extends PluginBase {
public static $test = [
"Angel"
];
public function onEnable(): void{
$this->getServer()->getAsyncPool()->submitTask(new AsyncEvilTask(
function() {
self::$test[0] = "Evil";
}, function() {
var_dump(self::$test);
}
));
}
}
Expected Output
A var_dump of an array containing an element: a string equal to Angel.
Actual Output
zend_mm_heap corrupted error with no more explanation
Environment
Summary
After much research, I found the source of a problem that happens to me by reproducing it at will.
It seems that there is a strange behavior with the modification of a static variable, through a callable in another thread than the one that created this callable.
The example code will speak better than my explanations which can be shaky
Reproducing Code
A class :
In a PocketMine-MP plugin class:
Expected Output
A var_dump of an array containing an element: a string equal to Angel.
Actual Output
zend_mm_heap corrupted
error with no more explanation