mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 08:39:53 +00:00
Do not persist SimpleChunkManager between async tasks
this is just asking for memory leaks.
This commit is contained in:
parent
dde2e7e66f
commit
7edfa3713b
@ -24,7 +24,6 @@ declare(strict_types=1);
|
||||
namespace pocketmine\world\generator;
|
||||
|
||||
use pocketmine\scheduler\AsyncTask;
|
||||
use pocketmine\world\SimpleChunkManager;
|
||||
use pocketmine\world\World;
|
||||
use function igbinary_serialize;
|
||||
use function igbinary_unserialize;
|
||||
@ -59,12 +58,11 @@ class GeneratorRegisterTask extends AsyncTask{
|
||||
}
|
||||
|
||||
public function onRun() : void{
|
||||
$manager = new SimpleChunkManager($this->worldHeight);
|
||||
/**
|
||||
* @var Generator $generator
|
||||
* @see Generator::__construct()
|
||||
*/
|
||||
$generator = new $this->generatorClass($this->seed, igbinary_unserialize($this->settings));
|
||||
ThreadLocalGeneratorContext::register(new ThreadLocalGeneratorContext($generator, $manager), $this->worldId);
|
||||
ThreadLocalGeneratorContext::register(new ThreadLocalGeneratorContext($generator, $this->worldHeight), $this->worldId);
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class PopulationTask extends AsyncTask{
|
||||
return;
|
||||
}
|
||||
$generator = $context->getGenerator();
|
||||
$manager = $context->getChunkManager();
|
||||
$manager = new SimpleChunkManager($context->getWorldHeight());
|
||||
|
||||
/** @var Chunk[] $chunks */
|
||||
$chunks = [];
|
||||
@ -124,8 +124,6 @@ class PopulationTask extends AsyncTask{
|
||||
foreach($chunks as $i => $c){
|
||||
$this->{"chunk$i"} = $c->isDirty() ? FastChunkSerializer::serializeWithoutLight($c) : null;
|
||||
}
|
||||
|
||||
$manager->cleanChunks();
|
||||
}
|
||||
|
||||
public function onCompletion() : void{
|
||||
|
@ -23,8 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\generator;
|
||||
|
||||
use pocketmine\world\SimpleChunkManager;
|
||||
|
||||
/**
|
||||
* Manages thread-local caches for generators and the things needed to support them
|
||||
*/
|
||||
@ -49,15 +47,15 @@ final class ThreadLocalGeneratorContext{
|
||||
|
||||
/** @var Generator */
|
||||
private $generator;
|
||||
/** @var SimpleChunkManager */
|
||||
private $chunkManager;
|
||||
/** @var int */
|
||||
private $worldHeight;
|
||||
|
||||
public function __construct(Generator $generator, SimpleChunkManager $chunkManager){
|
||||
public function __construct(Generator $generator, int $worldHeight){
|
||||
$this->generator = $generator;
|
||||
$this->chunkManager = $chunkManager;
|
||||
$this->worldHeight = $worldHeight;
|
||||
}
|
||||
|
||||
public function getGenerator() : Generator{ return $this->generator; }
|
||||
|
||||
public function getChunkManager() : SimpleChunkManager{ return $this->chunkManager; }
|
||||
public function getWorldHeight() : int{ return $this->worldHeight; }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user