Visual Studio 2010 的局部变量报告不稳定

发布于 2024-12-11 09:18:47 字数 682 浏览 0 评论 0原文

在我的一个名为 MoveMethod 的对象中,我有三个 TileGridArea,这是我创建的一种数据结构,用于存储相对于特定原点的列行对。

TileGridAreas 的操作相当基本,并且它们在该项目的许多其他区域中运行得很好,但是当我在 MoveMethod 中通过指针引用它们时,更改不会正确显示,因此它会搞砸所有寻路工作我正在努力实现。

我在此处第 25-27 行的构造函数中初始化了这三个值。

并在此处的第 2 行上专门执行第一个操作 编辑:似乎只允许 2 个显式链接(http://codepad.org/wXxBL7nb)

它正确地读取了 PreviewPath 为空,因此在第 5 行上执行了 addMember 函数我已经在调试中单步执行了它,并且完全没有理由不工作,但是当它从 addMember 函数返回到外部函数时,快速查看一下 本地窗口 显示,无论出于何种原因,它决定不添加到 PreviewPath,而是添加到 possibleDestinations。

这是 Visual Studio 的问题还是我的代码的问题?我发现当我所依赖的有关所涉及变量的准确信息的源完全错误时,调试对象的功能部分非常困难。

In one of my objects named MoveMethod, I have three TileGridAreas, a data structure I created for storing column-row pairs relative to a specific origin.

The TileGridAreas are fairly basic in their operation, and they function just fine in many other areas of this project, but when I refer to them by pointer within MoveMethod, the changes do not appear correctly, and as such it's gumming up all the pathfinding work I'm trying to accomplish.

I initialize the three in the constructor on lines 25-27 here.

And perform the first operation specifically on previewPath on line 2 here EDIT: only allowed 2 explicit links it seems(http://codepad.org/wXxBL7nb)

It correctly reads that previewPath is empty, and as such performs the addMember function on line 5. I've stepped through it in debug, and there is no reason at all for it not to work, but when it returns from the addMember function to the outer function, a quick look at the locals window shows that it has, for whatever arbitrary reason, decided to add not to previewPath but to possibleDestinations.

Is this an issue with visual studio or with my code? I'm finding it ridiculously difficult to debug the functional part of the object when the source I'm relying on for accurate information about the involved variables is flat out wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

早茶月光 2024-12-18 09:18:47

对我来说效果很好。我将代码缩减为最小的可运行版本 - 您将来应该自己执行此操作。

#include <assert.h>

class TileGridArea
{
public:
    TileGridArea() : changed (false) {}

    void addMember(int,int) {changed = true;}

    bool changed;
};

class MoveMethod
{
public:
    MoveMethod()
    {
        movePath = new TileGridArea();
        previewPath = new TileGridArea();
        possibleDestinations = new TileGridArea();
    }

    TileGridArea* movePath;
    TileGridArea* previewPath;
    TileGridArea* possibleDestinations;
};

int main()
{
    MoveMethod m;

    m.previewPath->addMember(3,4);
    assert(m.previewPath->changed);
    assert(!m.possibleDestinations->changed);
}

Works fine for me. I cut down the code to the smallest runnable version - you should do this yourself in future.

#include <assert.h>

class TileGridArea
{
public:
    TileGridArea() : changed (false) {}

    void addMember(int,int) {changed = true;}

    bool changed;
};

class MoveMethod
{
public:
    MoveMethod()
    {
        movePath = new TileGridArea();
        previewPath = new TileGridArea();
        possibleDestinations = new TileGridArea();
    }

    TileGridArea* movePath;
    TileGridArea* previewPath;
    TileGridArea* possibleDestinations;
};

int main()
{
    MoveMethod m;

    m.previewPath->addMember(3,4);
    assert(m.previewPath->changed);
    assert(!m.possibleDestinations->changed);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文