Visual C++ 应用程序在发布中的 main 之前崩溃,但在调试中运行良好

发布于 2024-07-10 08:11:51 字数 587 浏览 9 评论 0原文

在发布时,它会因未处理的异常而崩溃:std::length 错误。

调用堆栈如下所示:

msvcr90.dll!__set_flsgetvalue()  Line 256 + 0xc bytes   C
msvcr90.dll!__set_flsgetvalue()  Line 256 + 0xc bytes   C
msvcr90.dll!_getptd_noexit()  Line 616 + 0x7 bytes  C
msvcr90.dll!_getptd()  Line 641 + 0x5 bytes C
msvcr90.dll!rand()  Line 68 C
NEM.exe!CGAL::Random::Random()  + 0x34 bytes    C++
msvcr90.dll!_initterm(void (void)* * pfbegin=0x00000003, void (void)* * pfend=0x00345560)  Line 903 C
NEM.exe!__tmainCRTStartup()  Line 582 + 0x17 bytes  C
kernel32.dll!7c817067()     

有人有任何线索吗?

When in release it crashes with an unhandled exception: std::length error.

The call stack looks like this:

msvcr90.dll!__set_flsgetvalue()  Line 256 + 0xc bytes   C
msvcr90.dll!__set_flsgetvalue()  Line 256 + 0xc bytes   C
msvcr90.dll!_getptd_noexit()  Line 616 + 0x7 bytes  C
msvcr90.dll!_getptd()  Line 641 + 0x5 bytes C
msvcr90.dll!rand()  Line 68 C
NEM.exe!CGAL::Random::Random()  + 0x34 bytes    C++
msvcr90.dll!_initterm(void (void)* * pfbegin=0x00000003, void (void)* * pfend=0x00345560)  Line 903 C
NEM.exe!__tmainCRTStartup()  Line 582 + 0x17 bytes  C
kernel32.dll!7c817067()     

Has anyone got any clues?

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

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

发布评论

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

评论(4

離人涙 2024-07-17 08:11:51

检查堆栈转储:

InitTerm 只是一个函数,它遍历其他函数的列表并按步骤执行每个函数 - 除其他外,它还用于全局构造函数(启动时)、全局析构函数(关闭时)和 atexit 列表(也关闭时)。

您正在与 CGAL 链接,因为堆栈转储中的 CGAL::Random::Random 是由于 CGAL 定义了 default_random 的全局变量>CGAL::Random::Random 类型。 这就是为什么你的错误发生在 main 之前,正在构造 default_random

从 CGAL 源代码来看,它所做的一切都是调用标准 C srand(time(NULL)),然后调用本地 get_int,后者又调用标准 C >rand() 获取随机数。

但是,您没有进入第二阶段,因为您的堆栈转储仍在 srand() 内。

看起来就像它正在将您的线程惰性地转换为光纤,即,这是您第一次尝试在线程中执行某些操作,并且它必须在继续之前设置光纤本地存储。

因此,有几件事需要尝试和调查。

1/ 您是否在 XP 之前的版本上运行此代码? 我相信光纤本地存储(__set_flsgetvalue)是在 XP 中引入的。 虽然可能性不大,但无论如何我们都需要解决这个问题。

2/ 需要链接CGAL吗? 我假设您的应用程序需要 CGAL 库中的某些内容,否则不要与其链接。 这可能是另一个项目文件的遗留问题。

3/ 如果您确实使用CGAL,请确保您使用的是最新版本。 从 3.3 开始,它支持动态链接,这应该可以防止混合不同库版本(静态/动态和调试/非调试)的可能性。

4/ 你能尝试用VC8编译吗? CGAL 支持的平台还包括 VC9 (VS2008)。 您可能需要与 CGAL 团队本身跟进,看看他们是否正在提供该支持。

5/ 最后,您安装了 Boost 吗? 这是另一个远景,但无论如何值得一看。

如果这些建议都没有帮助,恐怕你就得等待比我更有见识的人来了。

祝你好运。

Examining the stack dump:

InitTerm is simply a function that walks a list of other functions and executes each in step - this is used for, amongst other things, global constructors (on startup), global destructors (on shutdown) and atexit lists (also on shutdown).

You are linking with CGAL, since that CGAL::Random::Random in your stack dump is due to the fact that CGAL defines a global variable called default_random of the CGAL::Random::Random type. That's why your error is happening before main, the default_random is being constructed.

From the CGAL source, all it does it call the standard C srand(time(NULL)) followed by the local get_int which, in turn, calls the standard C rand() to get a random number.

However, you're not getting to the second stage since your stack dump is still within srand().

It looks like it's converting your thread into a fiber lazily, i.e., this is the first time you've tried to do something in the thread and it has to set up fiber-local storage before continuing.

So, a couple of things to try and investigate.

1/ Are you running this code on pre-XP? I believe fiber-local storage (__set_flsgetvalue) was introduced in XP. This is a long shot but we need to clear it up anyway.

2/ Do you need to link with CGAL? I'm assuming your application needs something in the CGAL libraries, otherwise don't link with it. It may be a hangover from another project file.

3/ If you do use CGAL, make sure you're using the latest version. As of 3.3, it supports a dynamic linking which should prevent the possibility of mixing different library versions (both static/dynamic and debug/nondebug).

4/ Can you try to compile with VC8? The CGAL supported platforms do NOT yet include VC9 (VS2008). You may need to follow this up with the CGAL team itself to see if they're working on that support.

5/ And, finally, do you have Boost installed? That's another long shot but worth a look anyway.

If none of those suggestions help, you'll have to wait for someone more knowledgable than I to come along, I'm afraid.

Best of luck.

菊凝晚露 2024-07-17 08:11:51

main() 之前的崩溃通常是由全局或静态变量中的错误构造函数引起的。

看起来像类 Random 的构造函数。

Crashes before main() are usually caused by a bad constructor in a global or static variable.

Looks like the constructor for class Random.

吾家有女初长成 2024-07-17 08:11:51

您有 Random 类型的全局变量或静态变量吗? 您是否有可能在正确初始化它所在的库之前尝试构建它?

请注意,全局变量和静态变量的构造顺序并不固定,并且从调试到发布可能会发生变化。

Do you have a global or static variable of type Random? Is it possible that you're trying to construct it before the library it's in has been properly initialized?

Note that the order of construction of global and static variables is not fixed and might change going from debug to release.

≈。彩虹 2024-07-17 08:11:51

您能否更具体地说明您收到的错误? (未处理的异常 std::length 听起来很奇怪 - 我从未听说过)

据我所知,如果 FLS API 不可用,FlsGetValue 会自动回退到 TLS 对应项。

如果您仍然陷入困境,请在崩溃时获取进程的 .dmp 并将其发布(使用众多免费上传服务中的任何一个 - 并给我们一个链接)(听起来像是 SO 中缺少的功能 - 源/数据文件交换?)

Could you be more specific about the error you're receiving? (unhandled exception std::length sounds weird - i've never heard of it)

To my knowledge, FlsGetValue automatically falls back to TLS counterpart if FLS API is not available.

If you're still stuck, take .dmp of your process at the time of crash and post it (use any of the numerous free upload services - and give us a link) (Sounds like a missing feature in SO - source/data file exchange?)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文