diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 20627b1e..a9b37046 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -21,6 +21,7 @@ 3. This notice may not be removed or altered from any source distribution. using System; using System.Collections.Generic; using DotRecast.Core; +using DotRecast.Core.Buffers; using DotRecast.Core.Collections; using DotRecast.Core.Numerics; @@ -41,9 +42,9 @@ public class DtNavMeshQuery public DtNavMeshQuery(DtNavMesh nav) { m_nav = nav; - m_tinyNodePool = new DtNodePool(); m_nodePool = new DtNodePool(); m_openList = new DtNodeQueue(); + m_tinyNodePool = new DtNodePool(); } /// Returns random location on navmesh. @@ -386,8 +387,8 @@ public DtStatus FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, fl float s = frand.Next(); float t = frand.Next(); - float[] areas = new float[randomPolyVerts.Length / 3]; - RcVec3f pt = DtUtils.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas, s, t); + using var areas = RcRentedArray.Rent(randomPolyVerts.Length / 3); + RcVec3f pt = DtUtils.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas.AsArray(), s, t); ClosestPointOnPoly(randomPolyRef, pt, out var closest, out var _); randomRef = randomPolyRef; @@ -1793,7 +1794,9 @@ public DtStatus MoveAlongSurface(long startRef, RcVec3f startPos, RcVec3f endPos resultPos = RcVec3f.Zero; if (null != visited) + { visited.Clear(); + } // Validate input if (!m_nav.IsValidPolyRef(startRef) || !startPos.IsFinite() @@ -2245,7 +2248,7 @@ public DtStatus Raycast(long startRef, RcVec3f startPos, RcVec3f endPos, hit.path.Clear(); hit.pathCost = 0; - RcVec3f[] verts = new RcVec3f[m_nav.GetMaxVertsPerPoly() + 1]; + using var verts = RcRentedArray.Rent(m_nav.GetMaxVertsPerPoly() + 1); RcVec3f curPos = RcVec3f.Zero; RcVec3f lastPos = RcVec3f.Zero; @@ -2279,7 +2282,7 @@ public DtStatus Raycast(long startRef, RcVec3f startPos, RcVec3f endPos, nv++; } - bool intersects = DtUtils.IntersectSegmentPoly2D(startPos, endPos, verts, nv, out var tmin, out var tmax, out var segMin, out var segMax); + bool intersects = DtUtils.IntersectSegmentPoly2D(startPos, endPos, verts.AsArray(), nv, out var tmin, out var tmax, out var segMin, out var segMax); if (!intersects) { // Could not hit the polygon, keep the old t and report hit.