diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs index b73a92f..d42c02e 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs @@ -664,23 +664,8 @@ public class TestNavmeshSampleTool : ISampleTool } else if (_mode == RcTestNavmeshToolMode.PATHFIND_STRAIGHT) { - if (m_sposSet && m_eposSet && m_startRef != 0 && m_endRef != 0) - { - var polys = new List(); - var straightPath = new List(); - var status = _tool.FindStraightPath(navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, _enableRaycast, - ref polys, ref straightPath, _straightPathOption); - - if (status.Succeeded()) - { - m_polys = polys; - m_straightPath = straightPath; - } - } - else - { - m_straightPath = null; - } + _tool.FindStraightPath(navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, _enableRaycast, + ref m_polys, ref m_straightPath, _straightPathOption); } else if (_mode == RcTestNavmeshToolMode.PATHFIND_SLICED) { diff --git a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs index bc0b136..feb0f10 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs @@ -165,8 +165,19 @@ namespace DotRecast.Recast.Toolset.Tools public DtStatus FindStraightPath(DtNavMeshQuery navQuery, long startRef, long endRef, RcVec3f startPt, RcVec3f endPt, IDtQueryFilter filter, bool enableRaycast, ref List polys, ref List straightPath, int straightPathOptions) { - navQuery.FindPath(startRef, endRef, startPt, endPt, filter, ref polys, - new DtFindPathOption(enableRaycast ? DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE : 0, float.MaxValue)); + if (startRef == 0 || endRef == 0) + { + return DtStatus.DT_FAILURE; + } + + polys ??= new List(); + straightPath ??= new List(); + + polys.Clear(); + straightPath.Clear(); + + var opt = new DtFindPathOption(enableRaycast ? DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE : 0, float.MaxValue); + navQuery.FindPath(startRef, endRef, startPt, endPt, filter, ref polys, opt); if (0 >= polys.Count) return DtStatus.DT_FAILURE;