为什么 mingw 编译的 Game Maker 扩展在没有 -static 的情况下编译时会在退出时崩溃?

发布于 2024-11-07 20:56:22 字数 855 浏览 3 评论 0原文

我用 mingw 4.5.0 编译了一个 DLL,并将其用作 Game Maker 8.0 扩展。 Game Maker 动态加载 dll。一切似乎都正常(调用 dll 函数并提供正确的返回值),但是当我关闭 Game Maker 时,会弹出一个对话框:“Microsoft Visual C++ 运行时库”、“此应用程序已请求运行时以不寻常的方式终止。 ”之后,该进程继续在后台徘徊几秒钟,然后消失。

当 dll 的任何函数都没有被实际调用时,也会发生这种情况。没有 DllMain,所有静态/全局变量都是基本数据类型或 std::string(当我删除 std::strings 时实际上也会发生这种情况)。

该 dll 与 zlib 和 libpng 静态链接。当我将 -static 传递给链接器(我假设)也静态链接运行时时,问题似乎消失了。然而,这大大增加了我的 DLL 的大小,在我了解发生了什么之前,这充其量只是一种解决方法。

关于可能的原因有什么想法吗?

更新:实际上,这个问题似乎只在 Game Maker 中加载两个扩展时才会发生:一个带有与 -static 链接的 dll,另一个则没有。在没有 -static 的情况下链接两者会使问题消失。但是,我仍然不明白这个问题,因为 dll 从不直接交互或共享数据结构。

更新2:我最近发现这可能与Game Maker本身的奇怪行为有关。加载 DLL 时似乎全局变量未正确初始化,如果全局对象尝试释放它们不拥有的内存,则可能会导致卸载时崩溃。这意味着 -static 只是一个随机因素,它改变了与全局变量关联的未初始化内存的值。

更新 3:修改了上述内容以包含有关 Game Maker 扩展的信息,因为这可能与更新 2 相关。

I compile a DLL with mingw 4.5.0 and use it as a Game Maker 8.0 extension. Game Maker dynamically loads the dll. Everything appears to work (the dll functions are called and provide correct return values), but when I close Game Maker a dialog pops up: "Microsoft Visual C++ Runtime Library", "This application has requested the Runtime to terminate in an unusual way." After that, the process continues to linger in the background for a few seconds and then disappears.

This also happens when none of the functions of the dll are actually called. There is no DllMain, and all static/global variables are basic data types or std::string (it actually also happens when I remove the std::strings).

The dll statically links with zlib and libpng. The problem seems to vanish when I pass -static to the linker which (I assume) also links the runtime statically. However, this considerably inflates the size of my DLL, and it is at best a workaround until I understand what is going on.

Any ideas on what might be the cause?

Update: Actually, it seems that the problem only happens when two extensons are loaded in Game Maker: One with a dll linked with -static, and the other without. Linking both without -static makes the problem disappear. However, I still don't understand the problem, because the dlls never directly interact or share data structures.

Update 2: I recently found out that this might be related to strange behavior of Game Maker itself. It seems that global variables aren't initialized correctly when the DLL is loaded, which might cause a crash on unloading if global objects try to free memory they don't own. That would mean the -static was just a random factor that changed the value of the uninitialized memory the globals were associated with.

Update 3: Modified the above to include the info that this is about Game Maker extensions, since this is likely relevant as per Update 2.

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

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

发布评论

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

评论(1

话少心凉 2024-11-14 20:56:22

It's just a guess. Try to look into something like the "static initialization order fiasco" that is described here. It may be that your problem is more related to the destructors (since it happens on close).

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