From 643a3a70439d1e38af0dae0dd1f0cce4291e0049 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 17 Dec 2015 18:57:06 +0100 Subject: [PATCH] findNearestPoly now fails when nearestRef is null, and only assigns it when the function succeeds --- Detour/Source/DetourNavMeshQuery.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Detour/Source/DetourNavMeshQuery.cpp b/Detour/Source/DetourNavMeshQuery.cpp index 2361705..48f9c36 100644 --- a/Detour/Source/DetourNavMeshQuery.cpp +++ b/Detour/Source/DetourNavMeshQuery.cpp @@ -712,7 +712,8 @@ dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* exten { dtAssert(m_nav); - *nearestRef = 0; + if (!nearestRef) + return DT_FAILURE | DT_INVALID_PARAM; // Get nearby polygons from proximity grid. const int MAX_SEARCH = 128; @@ -721,6 +722,8 @@ dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* exten if (dtStatusFailed(queryPolygons(center, extents, filter, polys, &polyCount, MAX_SEARCH))) return DT_FAILURE | DT_INVALID_PARAM; + *nearestRef = 0; + if (polyCount == 0) return DT_SUCCESS;