2017-08-11 13 views
-2

我正在使用VS2015上的DirectX11應用程序。最近我遇到了由此msvcp140d.dll庫引起的運行時錯誤。時出現如下圖所示的錯誤的調用堆棧: enter image description heremsvcp140d.dll如何導致整數比較錯誤?

和代碼生成錯誤如下所示: enter image description here

至於我可以告訴的變量是可以接受的價值觀,所以我不確定究竟是什麼導致此msvcp140d.dll在此行代碼處中斷。這是否意味着這個DLL可能不正確?還是其他的東西出了問題?

帶有錯誤的函數是我實現的A *算法。

vector<pair<int, int>> NavigationManager::pathFinding(int startX, int startY, int endX, int endY) const{ 
vector<pair<int, int>> path; 
if (startX == endX&&startY == endY) 
    return path; 

Node ***nodeMap = new Node**[mapHeight]; 
for (int i = 0; i<mapHeight; ++i) 
{ 
    nodeMap[i] = new Node*[mapWidth]; 
    for (int j = 0; j<mapWidth; ++j) 
    { 
     if (map[i][j] != 1) { 
      nodeMap[i][j] = new Node(j, i); 
      nodeMap[i][j]->hValue = (abs(endX - j) + abs(endY - i)) * 10; 
     } 
     else 
      nodeMap[i][j] = nullptr; 
    } 
} 

auto comp = [](Node *a, Node *b) {return (a->gValue + a->hValue) > (b->gValue + a->hValue); }; 
priority_queue<Node*, vector<Node*>, decltype(comp)> pq(comp); 
vector<Node*> v; 
int currentX, currentY, currentGValue; 
Node *currentParent = nullptr; 
do 
{ 
    if (pq.empty()) 
    { 
     currentX = startX; 
     currentY = startY; 
     currentGValue = 0; 
    } 
    else 
    { 
     currentParent = pq.top(); 
     currentX = currentParent->x; 
     currentY = currentParent->y; 
     currentGValue = currentParent->gValue; 
     v.push_back(currentParent); 
     pq.pop(); 
    } 
    if (currentX == endX&&currentY == endY) 
     break; 

    if (currentX<mapWidth - 1 && map[currentY][currentX + 1] != 1) 
    { 
     if (nodeMap[currentY][currentX + 1]->gValue == 0) 
     { 
      nodeMap[currentY][currentX + 1]->gValue = currentGValue + 10; 
      nodeMap[currentY][currentX + 1]->parent = currentParent; 
      pq.push(nodeMap[currentY][currentX + 1]); 
     } 
     else if (currentGValue + 10<nodeMap[currentY][currentX + 1]->gValue) 
     { 
      nodeMap[currentY][currentX + 1]->gValue = currentGValue + 10; 
      nodeMap[currentY][currentX + 1]->parent = currentParent; 
     } 
    } 

    if (currentX<mapWidth - 1 && map[currentY][currentX + 1] != 1 && currentY<mapHeight - 1 && map[currentY + 1][currentX] != 1 && map[currentY + 1][currentX + 1] != 1) 
    { 
     if (nodeMap[currentY + 1][currentX + 1]->gValue == 0) 
     { 
      nodeMap[currentY + 1][currentX + 1]->gValue = currentGValue + 14; 
      nodeMap[currentY + 1][currentX + 1]->parent = currentParent; 
      pq.push(nodeMap[currentY + 1][currentX + 1]); 
     } 
     else if (currentGValue + 14<nodeMap[currentY + 1][currentX + 1]->gValue) 
     { 
      nodeMap[currentY + 1][currentX + 1]->gValue = currentGValue + 14; 
      nodeMap[currentY + 1][currentX + 1]->parent = currentParent; 
     } 
    } 

    if (currentY<mapHeight - 1 && map[currentY + 1][currentX] != 1) 
    { 
     if (nodeMap[currentY + 1][currentX]->gValue == 0) 
     { 
      nodeMap[currentY + 1][currentX]->gValue = currentGValue + 10; 
      nodeMap[currentY + 1][currentX]->parent = currentParent; 
      pq.push(nodeMap[currentY + 1][currentX]); 
     } 
     else if (currentGValue + 10<nodeMap[currentY + 1][currentX]->gValue) 
     { 
      nodeMap[currentY + 1][currentX]->gValue = currentGValue + 10; 
      nodeMap[currentY + 1][currentX]->parent = currentParent; 
     } 
    } 

    if (currentX>0 && map[currentY][currentX - 1] != 1 && currentY<mapHeight - 1 && map[currentY + 1][currentX] != 1 && map[currentY + 1][currentX - 1] != 1) 
    { 
     if (nodeMap[currentY + 1][currentX - 1]->gValue == 0) 
     { 
      nodeMap[currentY + 1][currentX - 1]->gValue = currentGValue + 14; 
      nodeMap[currentY + 1][currentX - 1]->parent = currentParent; 
      pq.push(nodeMap[currentY + 1][currentX - 1]); 
     } 
     else if (currentGValue + 14<nodeMap[currentY + 1][currentX - 1]->gValue) 
     { 
      nodeMap[currentY + 1][currentX - 1]->gValue = currentGValue + 14; 
      nodeMap[currentY + 1][currentX - 1]->parent = currentParent; 
     } 
    } 

    if (currentX>0 && map[currentY][currentX - 1] != 1) 
    { 
     if (nodeMap[currentY][currentX - 1]->gValue == 0) 
     { 
      nodeMap[currentY][currentX - 1]->gValue = currentGValue + 10; 
      nodeMap[currentY][currentX - 1]->parent = currentParent; 
      pq.push(nodeMap[currentY][currentX - 1]); 
     } 
     else if (currentGValue + 10<nodeMap[currentY][currentX - 1]->gValue) 
     { 
      nodeMap[currentY][currentX - 1]->gValue = currentGValue + 10; 
      nodeMap[currentY][currentX - 1]->parent = currentParent; 
     } 
    } 

    if (currentX>0 && map[currentY][currentX - 1] != 1 && currentY>0 && map[currentY - 1][currentX] != 1 && map[currentY - 1][currentX - 1] != 1) 
    { 
     if (nodeMap[currentY - 1][currentX - 1]->gValue == 0) 
     { 
      nodeMap[currentY - 1][currentX - 1]->gValue = currentGValue + 14; 
      nodeMap[currentY - 1][currentX - 1]->parent = currentParent; 
      pq.push(nodeMap[currentY - 1][currentX - 1]); 
     } 
     else if (currentGValue + 14<nodeMap[currentY - 1][currentX - 1]->gValue) 
     { 
      nodeMap[currentY - 1][currentX - 1]->gValue = currentGValue + 14; 
      nodeMap[currentY - 1][currentX - 1]->parent = currentParent; 
     } 
    } 

    if (currentY>0 && map[currentY - 1][currentX] != 1) 
    { 
     if (nodeMap[currentY - 1][currentX]->gValue == 0) 
     { 
      nodeMap[currentY - 1][currentX]->gValue = currentGValue + 10; 
      nodeMap[currentY - 1][currentX]->parent = currentParent; 
      pq.push(nodeMap[currentY - 1][currentX]); 
     } 
     else if (currentGValue + 10<nodeMap[currentY - 1][currentX]->gValue) 
     { 
      nodeMap[currentY - 1][currentX]->gValue = currentGValue + 10; 
      nodeMap[currentY - 1][currentX]->parent = currentParent; 
     } 
    } 

    if (currentX<mapWidth - 1 && map[currentY][currentX + 1] != 1 && currentY>0 && map[currentY - 1][currentX] != 1 && map[currentY - 1][currentX + 1] != 1) 
    { 
     if (nodeMap[currentY - 1][currentX + 1]->gValue == 0) 
     { 
      nodeMap[currentY - 1][currentX + 1]->gValue = currentGValue + 14; 
      nodeMap[currentY - 1][currentX + 1]->parent = currentParent; 
      pq.push(nodeMap[currentY - 1][currentX + 1]); 
     } 
     else if (currentGValue + 14<nodeMap[currentY - 1][currentX + 1]->gValue) 
     { 
      nodeMap[currentY - 1][currentX + 1]->gValue = currentGValue + 14; 
      nodeMap[currentY - 1][currentX + 1]->parent = currentParent; 
     } 
    } 
} while (!pq.empty()); 

if (v.size() == 0 || v[v.size() - 1]->x != endX || v[v.size() - 1]->y != endY) 
    return path; 

stack<pair<int, int>> s; 
if (!v.empty()) 
{ 
    Node *destination = v[v.size() - 1]; 
    while (destination) 
    { 
     s.push(pair<int, int>(destination->x, destination->y)); 
     destination = destination->parent; 
    } 
} 
while (!s.empty()) 
{ 
    path.push_back(s.top()); 
    s.pop(); 
} 
for (int i = 0; i<mapHeight; ++i) 
{ 
    for (int j = 0; j<mapWidth; ++j) 
    { 
     delete nodeMap[i][j]; 
    } 
    delete[] nodeMap[i]; 
} 
delete[] nodeMap; 

return path; 

}

+0

這個庫是一個C++運行時庫,它不太可能存在問題。在你自己的代碼中尋找問題。 – SergeyA

+0

81行就是在函數被調用返回的時候繼續執行這個函數的地方。可能是'pq.pop();'。將代碼發佈爲代碼,而不是截圖。 – 1201ProgramAlarm

回答

0

你改變物體在你的優先級隊列排序關鍵字。

查看一個典型的案例,如果一個節點的gValue爲零,則爲其分配一個gValue並將其添加(指向)到優先級隊列。稍後,當節點仍處於優先級隊列中時,您可能會更改該gValue。這可能導致排序順序全部混亂,打破容器依賴的順序,以及誰知道將會發生什麼。這就是爲什麼priority_queue::top()返回一個const引用。

如果您需要更改已經在pq中的元素,則需要將其刪除,更改該值,然後將其添加回去。