From 1cef39cb73f5a9130d2cb9d497ca44350fb401d8 Mon Sep 17 00:00:00 2001 From: worktycho Date: Fri, 8 May 2015 23:20:22 +0100 Subject: Move chunk position accesses after the chunk validity checks --- src/Mobs/Monster.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 84f58ff85..9df5bd930 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -264,12 +264,14 @@ bool cMonster::EnsureProperDestination(cChunk & a_Chunk) cChunk * Chunk = a_Chunk.GetNeighborChunk(m_FinalDestination.x, m_FinalDestination.z); BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; - int RelX = m_FinalDestination.x - Chunk->GetPosX() * cChunkDef::Width; - int RelZ = m_FinalDestination.z - Chunk->GetPosZ() * cChunkDef::Width; + if ((Chunk == nullptr) || !Chunk->IsValid()) { return false; } + + int RelX = m_FinalDestination.x - Chunk->GetPosX() * cChunkDef::Width; + int RelZ = m_FinalDestination.z - Chunk->GetPosZ() * cChunkDef::Width; // If destination in the air, go down to the lowest air block. while (m_FinalDestination.y > 0) -- cgit v1.2.3