gpt4 book ai didi

c++ - 为什么某些东西在调试器打开时永远不会崩溃?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:32:35 29 4
gpt4 key购买 nike

我的应用程序使用 GLUTesselator 来 segmentation 复杂的凹多边形。当我运行普通版本的 exe 时它随机崩溃,但如果我在 VS 中开始调试它永远不会崩溃。我在这里找到了这个,这基本上是我的问题:

The multi-thread debug CRT (/MTd) masks the problem, because, like

Windows does with processes spawned by a debugger, it provides to your program a debug heap, that is initialized to the 0xCD pattern. Probably somewhere you use some uninitialized area of memory from the heap as a pointer and you dereference it; with the two debug heaps you get away with it for some reason (maybe because at address 0xbaadf00d and 0xcdcdcdcd there's valid allocated memory), but with the "normal" heap (which is often initialized to 0) you get an access violation, because you dereference a NULL pointer.

问题是崩溃发生在 GLU32.dll 中,我无法找出为什么它有时会尝试取消引用空指针。当我的多边形变得相当大并且有很多点时,它似乎会这样做。我能做什么?

谢谢

最佳答案

生活中的一个事实是,有时程序在调试器中的行为会有所不同。在您的情况下,某些内存的初始化方式不同,并且布局也可能不同。并发程序中的另一个常见情况是时序不同,并且竞争条件在调试器中发生的频率通常较低。

您可以尝试手动将堆初始化为不同的值(或者查看 Visual Studio 中是否有此选项)。通常初始化为非零会捕获更多错误,但在您的情况下可能并非如此。您还可以尝试使用程序的内存映射来安排页面 0xcdcdc000 未映射。

Visual Studio 可以在访问特定内存地址时设置断点,您可以试试这个(与变量断点相比,它可能会显着降低您的程序速度)。

关于c++ - 为什么某些东西在调试器打开时永远不会崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3384066/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com