diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 02f8f78..2decd95 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -3407,7 +3407,7 @@ namespace DotRecast.Detour DtNode curNode = endNode; do { - path.Insert(0, curNode.id); + path.Add(curNode.id); DtNode nextNode = m_nodePool.GetNodeAtIdx(curNode.pidx); if (curNode.shortcut != null) { @@ -3417,14 +3417,14 @@ namespace DotRecast.Detour long id = curNode.shortcut[i]; if (id != curNode.id && id != nextNode.id) { - path.Insert(0, id); + path.Add(id); } } } curNode = nextNode; } while (curNode != null); - + path.Reverse(); return DtStatus.DT_SUCCSESS; } diff --git a/src/DotRecast.Detour/DtNodePool.cs b/src/DotRecast.Detour/DtNodePool.cs index 525451d..c334095 100644 --- a/src/DotRecast.Detour/DtNodePool.cs +++ b/src/DotRecast.Detour/DtNodePool.cs @@ -74,23 +74,21 @@ namespace DotRecast.Detour } } } + else + { + nodes = new List(); + m_map.Add(id, nodes); + } - return Create(id, state); + return Create(id, state, nodes); } - protected DtNode Create(long id, int state) + private DtNode Create(long id, int state, List nodes) { DtNode node = new DtNode(m_nodes.Count + 1); node.id = id; node.state = state; m_nodes.Add(node); - var hasNode = m_map.TryGetValue(id, out var nodes); - ; - if (nodes == null) - { - nodes = new List(); - m_map.Add(id, nodes); - } nodes.Add(node); return node;