为什么周期无休止?

嗨,大家好!

我想切换到UE4,现在尝试重复通过路点查找路标的功能,它在Unity中很好用,但是C ++中存在问题。据我了解,该函数具有无限循环,openList不能为空。我的C ++知识不足以解决问题。我将很高兴为您提供任何帮助!

TArray<FVector> UWaypointsPathfinding::GetPath(UWaypoint* startNode, UWaypoint* goalNode)
{
    UWaypoint* beginNode = startNode;
    set<UWaypoint*> openList;
    vector<UWaypoint*> closedList;

    openList.insert(startNode);
    startNode->previous = nullptr;
    startNode->distance = 0;


    while (!openList.empty())
    {
        startNode = *openList.begin();
        openList.erase(openList.begin());


        float dist = startNode->distance;
        closedList.push_back(startNode);
        if(&startNode == &goalNode) break;

        int l = startNode->nearest.Num();
        for (int i = 0; i < l; i++)
        {
            UWaypoint* node = startNode->nearest[i]->FindComponentByClass<UWaypoint>();
            if(find(closedList.begin(),closedList.end(),node) != closedList.end() || openList.find(node) != openList.end())
                continue;

            node->previous = startNode;
            node->distance = dist + FVector::Dist(node->GetOwner()->GetActorLocation(), startNode->GetOwner()->GetActorLocation());
            node->distance += FVector::Dist(node->GetOwner()->GetActorLocation(), goalNode->GetOwner()->GetActorLocation());

            openList.insert(startNode);
        }


    }

    // create path...

    return TArray<FVector>();
}