【发布时间】:2017-08-11 17:56:53
【问题描述】:
我正在 VS2015 上开发 DirectX11 应用程序。最近我遇到了一个由这个 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++ 运行时库,极不可能有问题。在你自己的代码中寻找问题。
-
第 81 行是当任何被调用的函数返回时,该函数的执行将恢复的地方。可能是
pq.pop();。将您的代码发布为代码,而不是屏幕截图。
标签: c++ dll visual-studio-2015 directx-11