From 0775ed75ea67f75d06b1f59363bc8e5e2f09409b Mon Sep 17 00:00:00 2001 From: mrcheko Date: Sat, 3 Sep 2016 17:41:03 +0300 Subject: [PATCH] fix zero div in getXAngleToDir --- apps/openmw/mwmechanics/pathfinding.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmechanics/pathfinding.cpp b/apps/openmw/mwmechanics/pathfinding.cpp index ef60a85a4..85e120d18 100644 --- a/apps/openmw/mwmechanics/pathfinding.cpp +++ b/apps/openmw/mwmechanics/pathfinding.cpp @@ -89,7 +89,8 @@ namespace MWMechanics float getXAngleToDir(const osg::Vec3f& dir) { - return -std::asin(dir.z() / dir.length()); + float dirLen = dir.length(); + return (dirLen != 0) ? -std::asin(dir.z() / dirLen) : 0; } float getZAngleToPoint(const ESM::Pathgrid::Point &origin, const ESM::Pathgrid::Point &dest) @@ -276,7 +277,7 @@ namespace MWMechanics const ESM::Pathgrid::Point &nextPoint = *mPath.begin(); osg::Vec3f dir = MakeOsgVec3(nextPoint) - osg::Vec3f(x,y,z); - return -std::asin(dir.z() / dir.length()); + return getXAngleToDir(dir); } bool PathFinder::checkPathCompleted(float x, float y, float tolerance)