Fix crash nav generation with impossibly-large grid

This commit is contained in:
s1lentq 2025-04-17 04:59:11 +07:00
parent 5bf71bdb18
commit 99d93ba8a7
2 changed files with 18 additions and 0 deletions

View File

@ -1793,6 +1793,13 @@ void GenerateNavigationAreaMesh()
break; break;
} }
if (!TheNavAreaList.size())
{
// If we somehow have no areas, don't try to create an impossibly-large grid
TheNavAreaGrid.Initialize(0, 0, 0, 0);
return;
}
Extent extent; Extent extent;
extent.lo.x = 9999999999.9f; extent.lo.x = 9999999999.9f;
extent.lo.y = 9999999999.9f; extent.lo.y = 9999999999.9f;
@ -4674,6 +4681,12 @@ void CNavAreaGrid::Initialize(float minX, float maxX, float minY, float maxY)
// Add an area to the grid // Add an area to the grid
void CNavAreaGrid::AddNavArea(CNavArea *area) void CNavAreaGrid::AddNavArea(CNavArea *area)
{ {
if (!m_grid)
{
// If we somehow have no grid (manually creating a nav area without loading or generating a mesh), don't crash
TheNavAreaGrid.Initialize(0, 0, 0, 0);
}
// add to grid // add to grid
const Extent *extent = area->GetExtent(); const Extent *extent = area->GetExtent();

View File

@ -846,6 +846,11 @@ NavErrorType LoadNavigationMap()
unsigned int count; unsigned int count;
result = navFile.Read(&count, sizeof(unsigned int)); result = navFile.Read(&count, sizeof(unsigned int));
if (count == 0)
{
return NAV_INVALID_FILE;
}
Extent extent; Extent extent;
extent.lo.x = 9999999999.9f; extent.lo.x = 9999999999.9f;
extent.lo.y = 9999999999.9f; extent.lo.y = 9999999999.9f;