开发者

Havok quit calls in destructor causing Unhandled exception

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 hkBaseSys开发者_如何学Gotem::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


I don't know anything about Havok, but it appears that you need to call the two quit functions in exactly that order:

  1. hkBaseSystem::quit();
  2. 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 of HKUTI!), or move the delete myhk; below hkBaseSystem::quit();.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜