From 2f2d68c29f5d241ba063f0e70a1c71d9a07acd0a Mon Sep 17 00:00:00 2001 From: ikpil Date: Wed, 24 Jan 2024 13:48:51 +0900 Subject: [PATCH] fix: SOH issue step3 (#41) - https://github.com/ikpil/DotRecast/issues/41 --- src/DotRecast.Detour/DtNavMeshQuery.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 82fe4fe..ad7debc 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -140,18 +140,18 @@ namespace DotRecast.Detour } // Randomly pick point on polygon. - float[] verts = new float[3 * m_nav.GetMaxVertsPerPoly()]; - float[] areas = new float[m_nav.GetMaxVertsPerPoly()]; - RcArrays.Copy(tile.data.verts, poly.verts[0] * 3, verts, 0, 3); + using var verts = RcRentedArray.RentDisposableArray(3 * m_nav.GetMaxVertsPerPoly()); + using var areas = RcRentedArray.RentDisposableArray(m_nav.GetMaxVertsPerPoly()); + RcArrays.Copy(tile.data.verts, poly.verts[0] * 3, verts.AsRentedArray(), 0, 3); for (int j = 1; j < poly.vertCount; ++j) { - RcArrays.Copy(tile.data.verts, poly.verts[j] * 3, verts, j * 3, 3); + RcArrays.Copy(tile.data.verts, poly.verts[j] * 3, verts.AsRentedArray(), j * 3, 3); } float s = frand.Next(); float t = frand.Next(); - var pt = DtUtils.RandomPointInConvexPoly(verts, poly.vertCount, areas, s, t); + var pt = DtUtils.RandomPointInConvexPoly(verts.AsRentedArray(), poly.vertCount, areas.AsRentedArray(), s, t); ClosestPointOnPoly(polyRef, pt, out var closest, out var _); randomRef = polyRef; @@ -389,8 +389,8 @@ namespace DotRecast.Detour 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.RentDisposableArray(randomPolyVerts.Length / 3); + RcVec3f pt = DtUtils.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas.AsRentedArray(), s, t); ClosestPointOnPoly(randomPolyRef, pt, out var closest, out var _); randomRef = randomPolyRef;