Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Havok quit calls in destructor causing Unhandled exception

Tags:

c++

havok

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

like image 467
Menglin Li Avatar asked Jan 30 '26 19:01

Menglin Li


1 Answers

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();.

like image 181
Daniel Gehriger Avatar answered Feb 02 '26 07:02

Daniel Gehriger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!