C ++ If语句已跳过

问题描述 投票:0回答:1

我正在使用两个ABB来实现冲突解决,但是似乎“ if(* yDepth> 0)”被编译器完全跳过了。当我在Visual Studio中将断点应用于该语句时,它回答“此断点当前不会被命中。指针是否有问题?我试图移动该语句的内容,更改条件,但它似乎总是跳过if有问题的陈述。

Vector2* normal = new Vector2();
Vector2* vFrom1to2 = new Vector2();
*vFrom1to2 = Vector2(b->getX() - a->getX(), b->getY() - a->getY());
float* xDepth = new float();
*xDepth = (a->getWidth()) + (b->getWidth()) - abs(vFrom1to2->x);
float* yDepth = new float();


if (*xDepth > 0) {

    *yDepth = (a->getHeight()) + (b->getHeight()) - abs(vFrom1to2->y);
    std::cout << "break";
    if (*yDepth > 0) { //this statement is skipped completely. yDepth is greater than 0 on testing.

        if (xDepth < yDepth) {
            if (vFrom1to2->x < 0) {
                normal->x == -1;
                normal->y == 0;
            }
            else {
                normal->x == 1;
                normal->y == 0;
            }

        }
        else {
            if (vFrom1to2->y < 0) {
                normal->x == 0;
                normal->y == -1;
            }
            else {
                normal->x == 0;
                normal->y == 1;
            }

        }

    }


}
c++ game-engine game-physics
1个回答
0
投票

在发布模式下-更确切地说,在优化处于启用状态时-编译器可以重新排序,重新排列,合并甚至删除代码行。这意味着您编写的代码行与实际生成的机器代码之间不再存在一对一的对应关系。这可能意味着某些代码行不能再分配断点,调试器在单步执行代码时可能会跳过。

通常,由于这个原因,最好在调试模式下进行调试。如果无法做到这一点,请在您感兴趣的行附近设置一个断点,并从此处开始逐步执​​行代码,而不是在您感兴趣的确切行上。

((读者注意:提问者澄清说他们在发布模式下遇到此问题)

© www.soinside.com 2019 - 2024. All rights reserved.