-2
我正在使用VS2015上的DirectX11應用程序。最近我遇到了由此msvcp140d.dll庫引起的運行時錯誤。時出現如下圖所示的錯誤的調用堆棧: msvcp140d.dll如何導致整數比較錯誤?
至於我可以告訴的變量是可以接受的價值觀,所以我不確定究竟是什麼導致此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&¤tY == 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;
}
這個庫是一個C++運行時庫,它不太可能存在問題。在你自己的代碼中尋找問題。 – SergeyA
81行就是在函數被調用返回的時候繼續執行這個函數的地方。可能是'pq.pop();'。將代碼發佈爲代碼,而不是截圖。 – 1201ProgramAlarm