World: fixed crash when using unloadChunk() during ChunkPopulateEvent, ChunkLoadEvent or when using ChunkListeners

I sure hope there isn't any other cases where this edge case can appear ...

closes #5022
This commit is contained in:
Dylan K. Taylor 2022-05-10 13:09:26 +01:00
parent 869d340f10
commit 593a4b65ea
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -3043,9 +3043,14 @@ class World implements ChunkManager{
unset($this->activeChunkPopulationTasks[$index]);
if($dirtyChunks === 0){
$promise = $this->chunkPopulationRequestMap[$index];
unset($this->chunkPopulationRequestMap[$index]);
$promise->resolve($chunk);
$promise = $this->chunkPopulationRequestMap[$index] ?? null;
if($promise !== null){
unset($this->chunkPopulationRequestMap[$index]);
$promise->resolve($chunk);
}else{
//Handlers of ChunkPopulateEvent, ChunkLoadEvent, or just ChunkListeners can cause this
$this->logger->debug("Unable to resolve population promise for chunk x=$x,z=$z - populated chunk was forcibly unloaded while setting modified chunks");
}
}else{
//request failed, stick it back on the queue
//we didn't resolve the promise or touch it in any way, so any fake chunk loaders are still valid and