Check if the destination chunk exists after leaving the source chunk

This fixes a crash if a player does a /refresh in the zeroeth chunk.
This commit is contained in:
dongresource 2021-05-02 19:51:59 +02:00
parent 1c3e1d83de
commit 2658ed5900

View File

@ -161,12 +161,13 @@ static void emptyChunk(ChunkPos chunkPos) {
void Chunking::updateEntityChunk(const EntityRef& ref, ChunkPos from, ChunkPos to) { void Chunking::updateEntityChunk(const EntityRef& ref, ChunkPos from, ChunkPos to) {
Entity* ent = ref.getEntity(); Entity* ent = ref.getEntity();
// move to other chunk's player set
untrackEntity(from, ref); // this will delete the chunk if it's empty
// if the new chunk doesn't exist, make it first // if the new chunk doesn't exist, make it first
if (!chunkExists(to)) if (!chunkExists(to))
newChunk(to); newChunk(to);
// move to other chunk's player set
untrackEntity(from, ref); // this will delete the chunk if it's empty
trackEntity(to, ref); trackEntity(to, ref);
// calculate viewable chunks from both points // calculate viewable chunks from both points