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.
This commit is contained in:
Kawe Mazidjatari 2024-10-11 01:15:45 +02:00
parent dabedb2c8b
commit b4b0e22d61

View File

@ -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()