这是我第一次在这里问问题,所以如果我有任何错误,请原谅我。
我目前在Windows 10企业版上使用Unity 2019.1.14f1,其Intel Xeon E5-1650 v4带有32.0 GB RAM,GeForce GTX 1080具有最新的驱动程序。
为提供一些有关此问题的信息,我设置了一个统一的场景,其中包含一堆带有 NavLinkProxy 类和 NavNodeProxy 类的对象,用于存储一些数据。这些用于生成路线,特别是使用Dijkstra的算法。下面是我使用的代码:
private static void DijkstraSearch(VenueManager venueManager, NavNodeProxy start, NavNodeProxy end)
{
// Priority queue
var pQueue = new BinaryHeap<NavNodeProxy>();
// Set cost of start node to 0
start._NavNodeInfo.MinCostToStart = 0;
// Add start node to priority queue
pQueue.Add(start);
do
{
// Remove node on top of heap and set it as node value
var node = pQueue.Remove();
List<NavLinkProxy> nodeLinks = venueManager._ActiveNavLinks.FindAll(result => (result._NavLinkInfo.n1 == node) || (result._NavLinkInfo.n2 == node));
for (int i = 0; i < nodeLinks.Count; i++)
{
NavNodeProxy connectingNode;
if (nodeLinks[i]._NavLinkInfo.n1._NavNodeInfo.id == node._NavNodeInfo.id)
connectingNode = nodeLinks[i]._NavLinkInfo.n2;
else
connectingNode = nodeLinks[i]._NavLinkInfo.n1;
if (connectingNode._NavNodeInfo.Visited)
continue;
if (connectingNode._NavNodeInfo.MinCostToStart == Mathf.Infinity || node._NavNodeInfo.MinCostToStart + nodeLinks[i]._NavLinkInfo.horizontalLength < connectingNode._NavNodeInfo.MinCostToStart)
{
connectingNode._NavNodeInfo.MinCostToStart = node._NavNodeInfo.MinCostToStart + nodeLinks[i]._NavLinkInfo.horizontalLength;
connectingNode._NavNodeInfo.NearestToStart = node;
if (!pQueue.heapList.Contains(connectingNode))
pQueue.Add(connectingNode);
}
}
node._NavNodeInfo.Visited = true;
if (node == end)
return;
} while (pQueue.heapList.Any());
}
该路线最初会正常生成,并且如果我也更改 end 的位置,则可以正常工作。
但是,当我更改 start 的位置并尝试生成路线时,Unity挂断了,通常保持完全无响应,并迫使我强制关闭它。
我尝试交换场景中的开始和结束节点对象,并重复上述步骤以获取完全相同的结果。除此之外,我不太确定会发生什么事给我这个结果。
编辑:使用正确的代码编辑了帖子。