C++ VS 调试器转移行为?

标签 c++ visual-studio debugging for-loop

我目前正在努力调试以下代码部分。我在 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/

相关文章:

c++ - Qt Webview 谷歌地图缓存

c++ - "spamming"boost::property_tree::read_json 时发生访问冲突

c++ 我应该打扰删除指向应用程序生命周期变量的指针吗?

C++:类之间的 "unresolved overload function type"

javascript - 如何在 Firefox 调试器中找到该变量的值?

c++ - 针对 Win10 SDK 构建时 TYPE_ALIGNMENT(LARGE_INTEGER) 不正确

visual-studio - 我怎样才能阻止 resharper 提示 html5 样板 html 标签?

visual-studio - Visual Studio将所有ImageAssets设置为Visible = false

c - 调试 C 程序(int 声明)

linux - 如何创建 Perl 调试器