Havok 退出析构函数中的调用导致未处理的异常
当我使用 havok 编程时,程序退出时崩溃,
我将 havok 函数封装到 C++ 类中以使主函数变得简单,并且我在类的析构函数中调用 havok quit 函数,但这可能会导致导致“未处理的异常”崩溃。
如果我从析构函数中取出havok的quit函数,并将其放在main函数中,那就可以了。我只是想知道为什么它在析构函数中不起作用但在主函数中起作用?
我的代码是:
int HK_CALL main(int argc, const char** argv)
{
HKUTI *myhk = new HKUTI(setupPhysics, 1000);
myhk->run(displayGraphics, 60, 30);
delete(myhk);
myhk = NULL;
hkBaseSystem::quit();
hkMemoryInitUtil::quit();
return 0;
}
2 havok quit 函数是 hkBaseSystem::quit();和 hkMemoryInitUtil::quit(); 如果我像上面的代码一样在 main 函数中调用它,程序将完美运行,但如果我将 2 quit 函数放在 HKUTI 类的析构函数中,则当程序尝试退出时它将崩溃。我看不出这两种方法有什么不同,谁能告诉我 C++ 析构函数中发生了什么?
非常感谢
When I programming using havok, I got a crash when the program quit,
I have envlope the havok functions to a C++ class to make the main function simple, and I call the havok quit functions in the destructor of my class, but it may lead to a "Unhandled exception" crash.
If I take out the havok's quite function from destructor, and put it in the main function, it will be fine. I just wondered why it does not work in the destructor but work in the main function?
my code is:
int HK_CALL main(int argc, const char** argv)
{
HKUTI *myhk = new HKUTI(setupPhysics, 1000);
myhk->run(displayGraphics, 60, 30);
delete(myhk);
myhk = NULL;
hkBaseSystem::quit();
hkMemoryInitUtil::quit();
return 0;
}
the 2 havok quit function is hkBaseSystem::quit(); and hkMemoryInitUtil::quit();
if I call it in the main function like the code above, the program will run perfectly, but if I put that 2 quit function in the destructor of the class HKUTI, it will crashed when the program trying to quit. I cant see any different of that 2 approach, could anyone please tell me what happend in the C++ destructor?
Thanks very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对 Havok 一无所知,但看来您需要按照完全相同的顺序调用两个退出函数:
hkBaseSystem::quit();
hkMemoryInitUtil::quit();
因此,如果将第二个调用移至
HKUTI
析构函数中,它将首先被调用。要么按照上面的顺序将这两个调用放入析构函数中(您可能需要确保只有一个HKUTI
实例!),或者移动delete myhk;
下面hkBaseSystem::quit();
。I don't know anything about Havok, but it appears that you need to call the two quit functions in exactly that order:
hkBaseSystem::quit();
hkMemoryInitUtil::quit();
So if you move the 2nd call into the
HKUTI
destructor, it will be called first. Either put both calls, in the order above in the destructor (you may want to make sure that there is only a single instance ofHKUTI
!), or move thedelete myhk;
belowhkBaseSystem::quit();
.首先,英特尔网站上的 Havok 论坛是了解 Havok 的好地方 -具体问题。我们的开发人员支持团队会定期回复。
崩溃的调用堆栈是什么?我猜测发生的事情是 HKUTI 的析构函数在调用 hkBaseSystem::quit() 后正在清理一些 Havok 对象。所有 Havok 类都会重写 new/delete 运算符,以使内存分配通过 hkMemorySystem 的实例。因此,如果在 hkBaseSystem::quit() 之后删除 Havok 对象,您将会崩溃,因为 hkMemorySystem::getInstance() 将返回 NULL。
希望有帮助。
First off, the Havok forums at Intel's site are a good place for Havok-specific questions. Our developer support team replies there regularly.
What's the callstack of the crash? My guess as to what's happening is that HKUTI's destructor is cleaning up some Havok objects after you call hkBaseSystem::quit(). All Havok classes override new/delete operators to make memory allocations go through an instance of hkMemorySystem. So if a Havok object is deleted after hkBaseSystem::quit(), you'll get a crash because hkMemorySystem::getInstance() will return NULL.
Hope that helps.