From 4112168f4aa672894e37a07c7f0803402151ef7d Mon Sep 17 00:00:00 2001 From: ikpil Date: Tue, 20 Jun 2023 21:13:25 +0900 Subject: [PATCH] bugfix - nullable straightPath --- src/DotRecast.Detour/DtNavMeshQuery.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 9cc15cc..d463c7e 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -1528,18 +1528,18 @@ namespace DotRecast.Detour /// @param[in] maxStraightPath The maximum number of points the straight path arrays can hold. [Limit: > 0] /// @param[in] options Query options. (see: #dtStraightPathOptions) /// @returns The status flags for the query. - public virtual DtStatus FindStraightPath(RcVec3f startPos, RcVec3f endPos, List path, + public virtual DtStatus FindStraightPath(RcVec3f startPos, RcVec3f endPos, List path, ref List straightPath, int maxStraightPath, int options) { - straightPath.Clear(); - - if (!RcVec3f.IsFinite(startPos) || !RcVec3f.IsFinite(endPos) - || null == path || 0 == path.Count || path[0] == 0 || maxStraightPath <= 0) + if (!RcVec3f.IsFinite(startPos) || !RcVec3f.IsFinite(endPos) || null == straightPath + || null == path || 0 == path.Count || path[0] == 0 || maxStraightPath <= 0) { return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } + straightPath.Clear(); + // TODO: Should this be callers responsibility? var closestStartPosRes = ClosestPointOnPolyBoundary(path[0], startPos, out var closestStartPos); if (closestStartPosRes.Failed()) @@ -1606,7 +1606,7 @@ namespace DotRecast.Detour // Ignore status return value as we're just about to return anyway. AppendVertex(closestEndPos, 0, path[i], ref straightPath, maxStraightPath); - + return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM | (straightPath.Count >= maxStraightPath ? DtStatus.DT_BUFFER_TOO_SMALL : DtStatus.DT_STATUS_NOTHING); } @@ -2794,7 +2794,6 @@ namespace DotRecast.Detour IDtQueryFilter filter, ref List resultRef, ref List resultParent) { - // Validate input if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || radius < 0 || !float.IsFinite(radius) || null == filter) @@ -2990,7 +2989,7 @@ namespace DotRecast.Detour { segmentVerts.Clear(); segmentRefs.Clear(); - + var status = m_nav.GetTileAndPolyByRef(refs, out var tile, out var poly); if (status.Failed()) {