我目前正在努力调试以下代码部分。我在 Windows 10 上使用 VS2015 社区版。
[(BR)] 是一个断点
以下是我的代码的(精简)版本。我基本上嵌套了从所有游戏对象中提取所有点(X 和 Y 坐标)的循环。
如您所见,我设置了两个断点。
我点击调试按钮,它在第一个断点处停止 - 成功。重要的局部变量 counterVertices 为零。也很棒。
然后我点击继续。它进入同一个断点三次。
然后我到达第二个断点。 counterVertices 显示为零。为什么?
int counterVertices = 0;
int counterIndices = 0;
int beginningOfPolygon = 0;
//GetData
for (auto& it : this->gameObjects) { //Iterate over all gameObjects
beginningOfPolygon = counterIndices;
for (int i = 0; i < it->getOutline().getNumber(); i++) { //Iterate over all points of the gameObject
[(BR)]this->vertices[counterVertices] = it->getRenderPoint(i).x;
counterVertices++;
this->vertices[counterVertices] = it->getRenderPoint(i).y;
counterVertices++;
[(BR)]if (this->vertices[counterVertices-2] == this->vertices[counterVertices-1] && this->vertices[counterVertices-1] == 0.0f) {
cout << "A point on 0/0." << endl;
}
this->vertices[counterVertices] = 0.0f;
counterVertices++;
//Add Line to draw
this->indices[counterIndices * 2] = counterIndices;
this->indices[(counterIndices * 2) + 1] = counterIndices + 1;
counterIndices++;
}
this->indices[(counterIndices * 2) - 1] = beginningOfPolygon;
}
我完全迷失了,因为这甚至不是我一开始想要解决的问题,而是一直在试图解决我原来的问题。
已经感谢您的宝贵时间
PS:我有整个过程的截图,过程是可以重现的。我可以清理并重建解决方案,重新启动并进行后空翻。调试行为不会改变。
PPS:程序的行为/工作方式表明 counterVertices 已正确增加,但调试器信息与此相矛盾。
最佳答案
确保您已关闭优化。优化确实会使调试变得困难,因为值将保存在寄存器中,直到需要时才会存储。而且代码流可能非常不直观。
关于C++ VS 调试器转移行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41401938/