1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-21 13:41:41 +00:00

Avoid access to the path vector element out of range

polygonPath.front() in some cases might reference to a first element of empty
vector. Copy the value into a local variable to be able to access later.
This commit is contained in:
elsid 2021-10-14 23:30:37 +02:00
parent ed1953b811
commit 79665cea66
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40

View file

@ -199,11 +199,14 @@ namespace DetourNavigator
++smoothPathSize; ++smoothPathSize;
break; break;
} }
else if (offMeshConnection && inRange(result->mResultPos, steerTarget->steerPos, slop))
dtPolyRef polyRef = polygonPath.front();
osg::Vec3f polyPos = result->mResultPos;
if (offMeshConnection && inRange(polyPos, steerTarget->steerPos, slop))
{ {
// Advance the path up to and over the off-mesh connection. // Advance the path up to and over the off-mesh connection.
dtPolyRef prevRef = 0; dtPolyRef prevRef = 0;
dtPolyRef polyRef = polygonPath.front();
std::size_t npos = 0; std::size_t npos = 0;
while (npos < polygonPath.size() && polyRef != steerTarget->steerPosRef) while (npos < polygonPath.size() && polyRef != steerTarget->steerPosRef)
{ {
@ -233,14 +236,11 @@ namespace DetourNavigator
} }
// Move position at the other side of the off-mesh link. // Move position at the other side of the off-mesh link.
if (dtStatusFailed(navMeshQuery.getPolyHeight(polygonPath.front(), endPos.ptr(), &iterPos.y()))) polyPos = endPos;
return Status::GetPolyHeightFailed;
iterPos.x() = endPos.x();
iterPos.z() = endPos.z();
} }
} }
if (dtStatusFailed(navMeshQuery.getPolyHeight(polygonPath.front(), result->mResultPos.ptr(), &iterPos.y()))) if (dtStatusFailed(navMeshQuery.getPolyHeight(polyRef, polyPos.ptr(), &iterPos.y())))
return Status::GetPolyHeightFailed; return Status::GetPolyHeightFailed;
iterPos.x() = result->mResultPos.x(); iterPos.x() = result->mResultPos.x();
iterPos.z() = result->mResultPos.z(); iterPos.z() = result->mResultPos.z();