fix: SOH issue (#41)

This commit is contained in:
ikpil 2024-01-23 22:49:36 +09:00 committed by ikpil
parent b81a5923a3
commit d8ae9f2297
2 changed files with 25 additions and 19 deletions

View File

@ -20,6 +20,7 @@ freely, subject to the following restrictions:
using System; using System;
using DotRecast.Core; using DotRecast.Core;
using DotRecast.Core.Buffers;
using DotRecast.Core.Numerics; using DotRecast.Core.Numerics;
@ -402,7 +403,7 @@ namespace DotRecast.Detour.Crowd
debug.Reset(); debug.Reset();
// Build sampling pattern aligned to desired velocity. // Build sampling pattern aligned to desired velocity.
float[] pat = new float[(DT_MAX_PATTERN_DIVS * DT_MAX_PATTERN_RINGS + 1) * 2]; using var pat = RcRentedArray.RentDisposableArray<float>((DT_MAX_PATTERN_DIVS * DT_MAX_PATTERN_RINGS + 1) * 2);
int npat = 0; int npat = 0;
int ndivs = m_params.adaptiveDivs; int ndivs = m_params.adaptiveDivs;

View File

@ -21,6 +21,7 @@ freely, subject to the following restrictions:
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using DotRecast.Core; using DotRecast.Core;
using DotRecast.Core.Buffers;
using DotRecast.Core.Collections; using DotRecast.Core.Collections;
using DotRecast.Core.Numerics; using DotRecast.Core.Numerics;
@ -36,6 +37,7 @@ namespace DotRecast.Detour
protected readonly DtNodeQueue m_openList; protected readonly DtNodeQueue m_openList;
protected DtQueryData m_query; protected DtQueryData m_query;
protected readonly DtNodePool m_tinyNodePool;
/// < Sliced query state. /// < Sliced query state.
public DtNavMeshQuery(DtNavMesh nav) public DtNavMeshQuery(DtNavMesh nav)
@ -44,6 +46,7 @@ namespace DotRecast.Detour
m_tinyNodePool = new DtNodePool(); m_tinyNodePool = new DtNodePool();
m_nodePool = new DtNodePool(); m_nodePool = new DtNodePool();
m_openList = new DtNodeQueue(); m_openList = new DtNodeQueue();
m_tinyNodePool = new DtNodePool();
} }
/// Returns random location on navmesh. /// Returns random location on navmesh.
@ -457,16 +460,16 @@ namespace DotRecast.Detour
} }
// Collect vertices. // Collect vertices.
float[] verts = new float[m_nav.GetMaxVertsPerPoly() * 3]; using var verts = RcRentedArray.RentDisposableArray<float>(m_nav.GetMaxVertsPerPoly() * 3);
float[] edged = new float[m_nav.GetMaxVertsPerPoly()]; using var edged = RcRentedArray.RentDisposableArray<float>(m_nav.GetMaxVertsPerPoly());
float[] edget = new float[m_nav.GetMaxVertsPerPoly()]; using var edget = RcRentedArray.RentDisposableArray<float>(m_nav.GetMaxVertsPerPoly());
int nv = poly.vertCount; int nv = poly.vertCount;
for (int i = 0; i < nv; ++i) for (int i = 0; i < nv; ++i)
{ {
RcArrays.Copy(tile.data.verts, poly.verts[i] * 3, verts, i * 3, 3); RcArrays.Copy(tile.data.verts, poly.verts[i] * 3, verts.AsRentedArray(), i * 3, 3);
} }
if (DtUtils.DistancePtPolyEdgesSqr(pos, verts, nv, edged, edget)) if (DtUtils.DistancePtPolyEdgesSqr(pos, verts.AsRentedArray(), nv, edged.AsRentedArray(), edget.AsRentedArray()))
{ {
closest = pos; closest = pos;
} }
@ -486,7 +489,7 @@ namespace DotRecast.Detour
int va = imin * 3; int va = imin * 3;
int vb = ((imin + 1) % nv) * 3; int vb = ((imin + 1) % nv) * 3;
closest = RcVecUtils.Lerp(verts, va, vb, edget[imin]); closest = RcVecUtils.Lerp(verts.AsRentedArray(), va, vb, edget[imin]);
} }
return DtStatus.DT_SUCCESS; return DtStatus.DT_SUCCESS;
@ -1793,7 +1796,9 @@ namespace DotRecast.Detour
resultPos = RcVec3f.Zero; resultPos = RcVec3f.Zero;
if (null != visited) if (null != visited)
{
visited.Clear(); visited.Clear();
}
// Validate input // Validate input
if (!m_nav.IsValidPolyRef(startRef) || !startPos.IsFinite() if (!m_nav.IsValidPolyRef(startRef) || !startPos.IsFinite()
@ -1822,7 +1827,7 @@ namespace DotRecast.Detour
var searchPos = RcVec3f.Lerp(startPos, endPos, 0.5f); var searchPos = RcVec3f.Lerp(startPos, endPos, 0.5f);
float searchRadSqr = RcMath.Sqr(RcVec3f.Distance(startPos, endPos) / 2.0f + 0.001f); float searchRadSqr = RcMath.Sqr(RcVec3f.Distance(startPos, endPos) / 2.0f + 0.001f);
float[] verts = new float[m_nav.GetMaxVertsPerPoly() * 3]; using var verts = RcRentedArray.RentDisposableArray<float>(m_nav.GetMaxVertsPerPoly() * 3);
while (0 < stack.Count) while (0 < stack.Count)
{ {
@ -1839,11 +1844,11 @@ namespace DotRecast.Detour
int nverts = curPoly.vertCount; int nverts = curPoly.vertCount;
for (int i = 0; i < nverts; ++i) for (int i = 0; i < nverts; ++i)
{ {
RcArrays.Copy(curTile.data.verts, curPoly.verts[i] * 3, verts, i * 3, 3); RcArrays.Copy(curTile.data.verts, curPoly.verts[i] * 3, verts.AsRentedArray(), i * 3, 3);
} }
// If target is inside the poly, stop search. // If target is inside the poly, stop search.
if (DtUtils.PointInPolygon(endPos, verts, nverts)) if (DtUtils.PointInPolygon(endPos, verts.AsRentedArray(), nverts))
{ {
bestNode = curNode; bestNode = curNode;
bestPos = endPos; bestPos = endPos;
@ -1856,7 +1861,7 @@ namespace DotRecast.Detour
// Find links to neighbours. // Find links to neighbours.
int MAX_NEIS = 8; int MAX_NEIS = 8;
int nneis = 0; int nneis = 0;
long[] neis = new long[MAX_NEIS]; using var neis = RcRentedArray.RentDisposableArray<long>(MAX_NEIS);
if ((curPoly.neis[j] & DtNavMesh.DT_EXT_LINK) != 0) if ((curPoly.neis[j] & DtNavMesh.DT_EXT_LINK) != 0)
{ {
@ -1896,11 +1901,11 @@ namespace DotRecast.Detour
// Wall edge, calc distance. // Wall edge, calc distance.
int vj = j * 3; int vj = j * 3;
int vi = i * 3; int vi = i * 3;
var distSqr = DtUtils.DistancePtSegSqr2D(endPos, verts, vj, vi, out var tseg); var distSqr = DtUtils.DistancePtSegSqr2D(endPos, verts.AsRentedArray(), vj, vi, out var tseg);
if (distSqr < bestDist) if (distSqr < bestDist)
{ {
// Update nearest distance. // Update nearest distance.
bestPos = RcVecUtils.Lerp(verts, vj, vi, tseg); bestPos = RcVecUtils.Lerp(verts.AsRentedArray(), vj, vi, tseg);
bestDist = distSqr; bestDist = distSqr;
bestNode = curNode; bestNode = curNode;
} }
@ -1920,7 +1925,7 @@ namespace DotRecast.Detour
// TODO: Maybe should use GetPortalPoints(), but this one is way faster. // TODO: Maybe should use GetPortalPoints(), but this one is way faster.
int vj = j * 3; int vj = j * 3;
int vi = i * 3; int vi = i * 3;
var distSqr = DtUtils.DistancePtSegSqr2D(searchPos, verts, vj, vi, out var _); var distSqr = DtUtils.DistancePtSegSqr2D(searchPos, verts.AsRentedArray(), vj, vi, out var _);
if (distSqr > searchRadSqr) if (distSqr > searchRadSqr)
{ {
continue; continue;
@ -2873,8 +2878,8 @@ namespace DotRecast.Detour
float radiusSqr = RcMath.Sqr(radius); float radiusSqr = RcMath.Sqr(radius);
float[] pa = new float[m_nav.GetMaxVertsPerPoly() * 3]; using var pa = RcRentedArray.RentDisposableArray<float>(m_nav.GetMaxVertsPerPoly() * 3);
float[] pb = new float[m_nav.GetMaxVertsPerPoly() * 3]; using var pb = RcRentedArray.RentDisposableArray<float>(m_nav.GetMaxVertsPerPoly() * 3);
while (0 < stack.Count) while (0 < stack.Count)
{ {
@ -2945,7 +2950,7 @@ namespace DotRecast.Detour
int npa = neighbourPoly.vertCount; int npa = neighbourPoly.vertCount;
for (int k = 0; k < npa; ++k) for (int k = 0; k < npa; ++k)
{ {
RcArrays.Copy(neighbourTile.data.verts, neighbourPoly.verts[k] * 3, pa, k * 3, 3); RcArrays.Copy(neighbourTile.data.verts, neighbourPoly.verts[k] * 3, pa.AsRentedArray(), k * 3, 3);
} }
bool overlap = false; bool overlap = false;
@ -2976,10 +2981,10 @@ namespace DotRecast.Detour
int npb = pastPoly.vertCount; int npb = pastPoly.vertCount;
for (int k = 0; k < npb; ++k) for (int k = 0; k < npb; ++k)
{ {
RcArrays.Copy(pastTile.data.verts, pastPoly.verts[k] * 3, pb, k * 3, 3); RcArrays.Copy(pastTile.data.verts, pastPoly.verts[k] * 3, pb.AsRentedArray(), k * 3, 3);
} }
if (DtUtils.OverlapPolyPoly2D(pa, npa, pb, npb)) if (DtUtils.OverlapPolyPoly2D(pa.AsRentedArray(), npa, pb.AsRentedArray(), npb))
{ {
overlap = true; overlap = true;
break; break;