Skip to content

Commit

Permalink
fix: SOH issue (#41)
Browse files Browse the repository at this point in the history
fix: SOH issue (#41)
- #41
ikpil committed May 2, 2024
1 parent 9e9a3f0 commit 34d154c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/DotRecast.Detour/DtNavMeshQuery.cs
Original file line number Diff line number Diff line change
@@ -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<float>(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<RcVec3f>(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.

0 comments on commit 34d154c

Please sign in to comment.