Missing ref in dtCreateNavMeshData
Hi. You might want to add by-ref access to dtPoly's and dtPolyDetail's in dtCreateNavMeshData method. Currently you are writing data to stack instead of native memory.
// Store polygons
// Mesh polys
var src = @params->polys;
for (int i = 0; i < @params->polyCount; ++i)
{
ref dtPoly p = ref navPolys[i]; // <-- here and in some other places, you need to use ref or *
p.vertCount = 0;
p.flags = @params->polyFlags[i];
p.setArea(@params->polyAreas[i]);
You also probably need to multiply by 3 in dtPointInPolygon method and in other similar methods:
public static bool dtPointInPolygon(float* pt, float* verts, int nverts)
{
return dtPointInPolygon(new ReadOnlySpan<float>(pt, 3), new ReadOnlySpan<float>(verts, nverts * 3), nverts);
//^here
}
Another major bug is in connectIntLinks method:
// Skip hard and non-internal edges.
if (poly->neis[j] == 0 || (poly->neis[j] & DT_EXT_LINK) != 0) //<-- Here you need to check for 0 instead of 1.
continue;
Those fixes were enough to make basic pathfinding work, but at this point I am not sure what else is broken. Clearly the port is untested, would be nice to have this info in a readme. Hope this helps fix things up, cheers.
Hey @nikita-one. I'm trying to port this over to Unity using the data oriented technology stack and jobs. I've got Recast converted, but Detour is giving me hard crashes, even after the modifications you advised here, which were very helpful. Did you make any additional changes other than the ones you listed?