Skip to content

Commit

Permalink
fix: SOH issue step3 (#41)
Browse files Browse the repository at this point in the history
- #41
  • Loading branch information
ikpil committed Jan 24, 2024
1 parent 246faf8 commit cd6321a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/DotRecast.Detour/DtNavMeshQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,18 @@ public DtStatus FindRandomPoint(IDtQueryFilter filter, IRcRand frand, out long r
}

// 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<float>(3 * m_nav.GetMaxVertsPerPoly());
using var areas = RcRentedArray.RentDisposableArray<float>(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;
Expand Down Expand Up @@ -386,8 +386,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.RentDisposableArray<float>(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;
Expand Down

0 comments on commit cd6321a

Please sign in to comment.