Core/Misc: Add a validity check for coordinates, prevents crashes

This commit is contained in:
Elron103
2012-03-11 15:45:21 +01:00
parent dc55d9ed13
commit e36027e90b

View File

@@ -2674,6 +2674,14 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float
pos.m_positionZ += 2.0f;
destx = pos.m_positionX + dist * cos(angle);
desty = pos.m_positionY + dist * sin(angle);
// Prevent invalid coordinates here, position is unchanged
if (!Trinity::IsValidMapCoord(destx, desty))
{
sLog->outCrash("WorldObject::MovePositionToFirstCollision invalid coordinates X: %f and Y: %f were passed!", destx, desty);
return;
}
ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true);
floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, pos.m_positionZ, true);
destz = fabs(ground - pos.m_positionZ) <= fabs(floor - pos.m_positionZ) ? ground : floor;