From b165a3afed51ce3432c99767fbb16bf0aa4786cf Mon Sep 17 00:00:00 2001 From: ikpil Date: Mon, 6 May 2024 14:34:46 +0900 Subject: [PATCH] SOH issue #41 - https://github.com/ikpil/DotRecast/issues/41 --- src/DotRecast.Detour/DtPathUtils.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/DotRecast.Detour/DtPathUtils.cs b/src/DotRecast.Detour/DtPathUtils.cs index 7534f29..e5e2dcc 100644 --- a/src/DotRecast.Detour/DtPathUtils.cs +++ b/src/DotRecast.Detour/DtPathUtils.cs @@ -96,7 +96,9 @@ namespace DotRecast.Detour } // Get connected polygons - List neis = new List(); + const int maxNeis = 16; + Span neis = stackalloc long[maxNeis]; + int nneis = 0; var status = navQuery.GetAttachedNavMesh().GetTileAndPolyByRef(path[0], out var tile, out var poly); if (status.Failed()) @@ -110,7 +112,8 @@ namespace DotRecast.Detour DtLink link = tile.links[k]; if (link.refs != 0) { - neis.Add(link.refs); + if (nneis < maxNeis) + neis[nneis++] = link.refs; } } @@ -120,7 +123,7 @@ namespace DotRecast.Detour int cut = 0; for (int i = Math.Min(maxLookAhead, path.Count) - 1; i > 1 && cut == 0; i--) { - for (int j = 0; j < neis.Count; j++) + for (int j = 0; j < nneis; j++) { if (path[i] == neis[j]) {