mirror of
https://github.com/recastnavigation/recastnavigation.git
synced 2026-08-13 08:59:25 +00:00
Fix for Issue 55: Negative array access in dtNavMesh::raycast()
This commit is contained in:
@@ -35,6 +35,19 @@
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
static int loadBin(const char* path, unsigned char** data)
|
||||
{
|
||||
FILE* fp = fopen(path, "rb");
|
||||
if (!fp) return 0;
|
||||
fseek(fp, 0, SEEK_END);
|
||||
int size = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
*data = new unsigned char[size];
|
||||
fread(*data, size, 1, fp);
|
||||
fclose(fp);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
Sample_Debug::Sample_Debug() :
|
||||
m_chf(0),
|
||||
@@ -44,13 +57,13 @@ Sample_Debug::Sample_Debug() :
|
||||
|
||||
// Test
|
||||
m_chf = new rcCompactHeightfield;
|
||||
if (!duReadCompactHeightfield(*m_chf, "test.chf"))
|
||||
if (!duReadCompactHeightfield(*m_chf, "Tile_-13_-14_chf.bin"))
|
||||
{
|
||||
delete m_chf;
|
||||
m_chf = 0;
|
||||
}
|
||||
|
||||
if (m_chf)
|
||||
/* if (m_chf)
|
||||
{
|
||||
unsigned short ymin = 0xffff;
|
||||
unsigned short ymax = 0;
|
||||
@@ -68,7 +81,46 @@ Sample_Debug::Sample_Debug() :
|
||||
maxSpans = rcMax(maxSpans, (int)m_chf->cells[i].count);
|
||||
}
|
||||
printf("maxSpans = %d\n", maxSpans);
|
||||
}*/
|
||||
|
||||
|
||||
/* const float orig[3] = {0,0,0};
|
||||
m_navMesh = new dtNavMesh;
|
||||
m_navMesh->init(orig, 133.333f,133.333f, 2048, 4096, 4096);
|
||||
|
||||
unsigned char* data = 0;
|
||||
int dataSize = 0;
|
||||
|
||||
// Tile_-13_-14.bin is basically just the bytes that was output by Detour. It should be loaded at X: -13 and Y: -14.
|
||||
|
||||
dataSize = loadBin("Tile_-13_-13.bin", &data);
|
||||
if (dataSize > 0)
|
||||
{
|
||||
m_navMesh->addTileAt(-13,-13, data, dataSize, true);
|
||||
dtMeshHeader* header = (dtMeshHeader*)data;
|
||||
vcopy(m_bmin, header->bmin);
|
||||
vcopy(m_bmax, header->bmax);
|
||||
}
|
||||
|
||||
dataSize = loadBin("Tile_-13_-14.bin", &data);
|
||||
if (dataSize > 0)
|
||||
{
|
||||
m_navMesh->addTileAt(-13,-14, data, dataSize, true);
|
||||
}
|
||||
|
||||
dataSize = loadBin("Tile_-14_-14.bin", &data);
|
||||
if (dataSize > 0)
|
||||
{
|
||||
m_navMesh->addTileAt(-14,-14, data, dataSize, true);
|
||||
}
|
||||
|
||||
const float ext[3] = {40,100,40};
|
||||
const float center[3] = { -1667.9491f, 135.52649f, -1680.6149f };
|
||||
dtQueryFilter filter;
|
||||
m_ref = m_navMesh->findNearestPoly(center, ext, &filter, 0);
|
||||
|
||||
vcopy(m_ext, ext);
|
||||
vcopy(m_center, center);*/
|
||||
}
|
||||
|
||||
Sample_Debug::~Sample_Debug()
|
||||
@@ -99,6 +151,18 @@ void Sample_Debug::handleRender()
|
||||
// duDebugDrawCompactHeightfieldSolid(&dd, *m_chf);
|
||||
}
|
||||
|
||||
if (m_navMesh)
|
||||
duDebugDrawNavMesh(&dd, m_navMesh, DU_DRAWNAVMESH_CLOSEDLIST|DU_DRAWNAVMESH_OFFMESHCONS);
|
||||
|
||||
if (m_ref)
|
||||
duDebugDrawNavMeshPoly(&dd, m_navMesh, m_ref, duRGBA(255,0,0,128));
|
||||
|
||||
float bmin[3], bmax[3];
|
||||
vsub(bmin, m_center, m_ext);
|
||||
vadd(bmax, m_center, m_ext);
|
||||
duDebugDrawBoxWire(&dd, bmin[0],bmin[1],bmin[2], bmax[0],bmax[1],bmax[2], duRGBA(255,255,255,128), 1.0f);
|
||||
duDebugDrawCross(&dd, m_center[0], m_center[1], m_center[2], 1.0f, duRGBA(255,255,255,128), 2.0f);
|
||||
|
||||
if (m_cset)
|
||||
duDebugDrawRawContours(&dd, *m_cset);
|
||||
}
|
||||
@@ -114,12 +178,18 @@ void Sample_Debug::handleMeshChanged(InputGeom* geom)
|
||||
|
||||
const float* Sample_Debug::getBoundsMin()
|
||||
{
|
||||
if (m_navMesh)
|
||||
return m_bmin;
|
||||
|
||||
if (!m_chf) return 0;
|
||||
return m_chf->bmin;
|
||||
}
|
||||
|
||||
const float* Sample_Debug::getBoundsMax()
|
||||
{
|
||||
if (m_navMesh)
|
||||
return m_bmax;
|
||||
|
||||
if (!m_chf) return 0;
|
||||
return m_chf->bmax;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user