mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 21:24:58 +00:00
Potential fix for infinite recursion in pathfinding
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
|
using ICD.Common.Utils.Collections;
|
||||||
|
|
||||||
namespace ICD.Common.Utils
|
namespace ICD.Common.Utils
|
||||||
{
|
{
|
||||||
@@ -103,11 +104,21 @@ namespace ICD.Common.Utils
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static IEnumerable<T> GetPath<T>(T start, IDictionary<T, T> nodeParents)
|
private static IEnumerable<T> GetPath<T>(T start, IDictionary<T, T> nodeParents)
|
||||||
{
|
{
|
||||||
|
IcdHashSet<T> visited = new IcdHashSet<T>();
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
yield return start;
|
yield return start;
|
||||||
if (!nodeParents.TryGetValue(start, out start))
|
visited.Add(start);
|
||||||
|
|
||||||
|
T next;
|
||||||
|
if (!nodeParents.TryGetValue(start, out next))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (visited.Contains(next))
|
||||||
|
break;
|
||||||
|
|
||||||
|
start = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user