Skip to content

Commit

Permalink
Fix for crash when generating a map after new scene load
Browse files Browse the repository at this point in the history
  • Loading branch information
KimLS committed Jan 13, 2016
1 parent 2f56712 commit cade414
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions map_edit/module_navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ void ModuleNavigation::OnSceneLoad(const char *zone_name)

if (m_nav_mesh) {
dtFreeNavMesh(m_nav_mesh);
m_nav_mesh = nullptr;
}

if (!LoadNavSettings()) {
Expand Down Expand Up @@ -1211,13 +1212,15 @@ void ModuleNavigation::LoadNavMesh()
uint32_t number_of_tiles = 0;
if (fread(&number_of_tiles, sizeof(uint32_t), 1, f) != 1) {
dtFreeNavMesh(m_nav_mesh);
m_nav_mesh = nullptr;
fclose(f);
return;
}

dtNavMeshParams params;
if (fread(&params, sizeof(dtNavMeshParams), 1, f) != 1) {
dtFreeNavMesh(m_nav_mesh);
m_nav_mesh = nullptr;
fclose(f);
return;
}
Expand All @@ -1226,6 +1229,7 @@ void ModuleNavigation::LoadNavMesh()
if (dtStatusFailed(status))
{
dtFreeNavMesh(m_nav_mesh);
m_nav_mesh = nullptr;
fclose(f);
return;
}
Expand All @@ -1235,26 +1239,30 @@ void ModuleNavigation::LoadNavMesh()
uint32_t tile_ref = 0;
if (fread(&tile_ref, sizeof(uint32_t), 1, f) != 1) {
dtFreeNavMesh(m_nav_mesh);
m_nav_mesh = nullptr;
fclose(f);
return;
}

int32_t data_size = 0;
if (fread(&data_size, sizeof(int32_t), 1, f) != 1) {
dtFreeNavMesh(m_nav_mesh);
m_nav_mesh = nullptr;
fclose(f);
return;
}

if (!tile_ref || !data_size) {
dtFreeNavMesh(m_nav_mesh);
m_nav_mesh = nullptr;
fclose(f);
return;
}

unsigned char* data = (unsigned char*)dtAlloc(data_size, DT_ALLOC_PERM);
if (fread(data, data_size, 1, f) != 1) {
dtFreeNavMesh(m_nav_mesh);
m_nav_mesh = nullptr;
fclose(f);
return;
}
Expand Down

0 comments on commit cade414

Please sign in to comment.