From b4b0e22d61d580d78a86fea9187732abdc59507d Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 11 Oct 2024 01:15:45 +0200 Subject: [PATCH] Recast: fix crash in prune tool when initiating NavMesh flood algorithm dtNavMeshQuery::findNearestPoly can return an error flag, and the function cal also succeed while returning a NULL polyref. Both need to be checked before the algorithm is called. Also moved the memory allocation for flags inside this new check to avoid allocating for nothing. --- src/naveditor/NavMeshPruneTool.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/naveditor/NavMeshPruneTool.cpp b/src/naveditor/NavMeshPruneTool.cpp index 14aca0a3..e15c2f01 100644 --- a/src/naveditor/NavMeshPruneTool.cpp +++ b/src/naveditor/NavMeshPruneTool.cpp @@ -294,18 +294,20 @@ void NavMeshPruneTool::handleClick(const float* s, const float* p, const int /*v rdVcopy(m_hitPos, p); m_hitPosSet = true; - if (!m_flags) - { - m_flags = new NavmeshFlags; - m_flags->init(nav); - } - const float halfExtents[3] = { 2, 2, 4 }; dtQueryFilter filter; dtPolyRef ref = 0; - query->findNearestPoly(p, halfExtents, &filter, &ref, 0); - floodNavmesh(nav, m_flags, ref, 1); + if (dtStatusSucceed(query->findNearestPoly(p, halfExtents, &filter, &ref, 0)) && ref) + { + if (!m_flags) + { + m_flags = new NavmeshFlags; + m_flags->init(nav); + } + + floodNavmesh(nav, m_flags, ref, 1); + } } void NavMeshPruneTool::handleToggle()