Closed AqlaSolutions closed 9 years ago
Yep, it's definitely threading issue.
var parameters = NavMeshGenerationSettings.Default;
parameters.AgentHeight = settings.MaxHeight;
parameters.AgentWidth = 1;
parameters.MaxClimb = settings.MaxClimb;
Triangle3[] tris = TriangleEnumerable.FromTriangle(level.GetTriangles(), 0, level.GetTriangles().Length).ToArray();
Thread.MemoryBarrier();
Enumerable.Range(1, 1000)
.AsParallel()
.Select(x => SharpNav.NavMesh.Generate(tris, parameters)).ToArray();
Yeah, without looking at the code I'm pretty sure I can pinpoint a Recast pull-request that added the breaking change. As triangles are getting voxelized, there was an optimization that stored intermediate variables in a static array. It should be somewhere in MathHelper.cs
.
The solution would be to either pass the array in as a parameter or use the older method when thread-safety is desired. In the future I'd also like to parallelize the generation process anyways, since it's so easy with the Task Parallel Library.
I'm about to get on a flight, I'll make an attempt at fixing this on the plane.
Let me know if that commit fixes your issue, I'll leave the issue open for the time being.
Yes, it works now. Thanks!
The same old obj: https://www.dropbox.com/s/jymf3n0oqwfhidr/Fighting_scene_navmesh.obj?dl=0
Sometimes (perhaps in multithread environment) it throws: http://clip2net.com/clip/m203122/86185-clip-78kb.png?nocache=1
I'll try to investigate this further...