From 5c457363478d609660cdf89b7e5f13cef1a0f669 Mon Sep 17 00:00:00 2001 From: Kromster80 Date: Tue, 6 Jan 2015 23:26:14 +0300 Subject: [PATCH 1/2] MAX_SEARCH constant instead of hardcoded value --- Detour/Source/DetourNavMeshQuery.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Detour/Source/DetourNavMeshQuery.cpp b/Detour/Source/DetourNavMeshQuery.cpp index 3d283ac..5fbc83e 100644 --- a/Detour/Source/DetourNavMeshQuery.cpp +++ b/Detour/Source/DetourNavMeshQuery.cpp @@ -704,7 +704,7 @@ dtStatus dtNavMeshQuery::getPolyHeight(dtPolyRef ref, const float* pos, float* h /// @p nearestRef before using @p nearestPt. /// /// @warning This function is not suitable for large area searches. If the search -/// extents overlaps more than 128 polygons it may return an invalid result. +/// extents overlaps more than MAX_SEARCH (128) polygons it may return an invalid result. /// dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* extents, const dtQueryFilter* filter, @@ -715,9 +715,10 @@ dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* exten *nearestRef = 0; // Get nearby polygons from proximity grid. - dtPolyRef polys[128]; + const int MAX_SEARCH = 128; + dtPolyRef polys[MAX_SEARCH]; int polyCount = 0; - if (dtStatusFailed(queryPolygons(center, extents, filter, polys, &polyCount, 128))) + if (dtStatusFailed(queryPolygons(center, extents, filter, polys, &polyCount, MAX_SEARCH))) return DT_FAILURE | DT_INVALID_PARAM; // Find nearest polygon amongst the nearby polygons. From 3ca4db48642958bdebeb33863ae16506f8a57afe Mon Sep 17 00:00:00 2001 From: Kromster80 Date: Thu, 19 Feb 2015 14:03:59 +0300 Subject: [PATCH 2/2] Fixed loop overrun --- Recast/Source/RecastMesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Recast/Source/RecastMesh.cpp b/Recast/Source/RecastMesh.cpp index 38b45fe..51634c7 100644 --- a/Recast/Source/RecastMesh.cpp +++ b/Recast/Source/RecastMesh.cpp @@ -747,7 +747,7 @@ static bool removeVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned short } // Remove vertex. - for (int i = (int)rem; i < mesh.nverts; ++i) + for (int i = (int)rem; i < mesh.nverts - 1; ++i) { mesh.verts[i*3+0] = mesh.verts[(i+1)*3+0]; mesh.verts[i*3+1] = mesh.verts[(i+1)*3+1];