Deleting a joint

alberts

12-09-2006 22:41:48

My program crash after deleting a joint. The way I have found to solve this issue is stoping the program some miliseconds after deleting the joint.

delete ballJoint;
Sleep(500);

Is this the only solution?

Thanks !! :)

HexiDave

13-09-2006 00:20:26

Delete it at the end of a frame (in frameEnded) - Newton may be grabbing for the information during that frame, so at the end you just disconnect it and delete it and all should be well - if that doesn't work, post some code showing how/when/what you're doing.

alberts

13-09-2006 15:20:36

Thanks for your reply!!

I've tried your suggestion but it doesnt work :( Here is the code involved. SimpleFlightSimApp inherits from baseapplication, which is created by the ogre wizard.

void SimpleFlightSimApp::createScene(void)
{
// Set ambient light
mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));

// Create a light
Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20,80,50);

mAirplane = new Airplane(mWorld,this->mSceneMgr);
}


Airplane::Airplane(OgreNewt::World* newtonWorld,Ogre::SceneManager* ogreSceneManager)
{
mWorld = newtonWorld;
mSceneManager = ogreSceneManager;

...

mFuselage = makeSimpleBox(*mFuselageSize,mFuselageMass,Ogre::Vector3(0,0,0),orient,"fuselage");
mFuselage->setStandardForceCallback();
mFuselage->setAutoFreeze(0);

...

ballJoint = new OgreNewt::BasicJoints::BallAndSocket(mWorld,mFuselage,NULL,Ogre::Vector3(0,10,0));

...
}

bool SimpleFlightSimApp::frameEnded(const FrameEvent& evt)
{
BaseApplication::frameEnded(evt); // only call to updatestat

if(mLaunch)
{
mAirplane->Launch();
}

return true;
}

void Airplane::Launch()
{
delete ballJoint;
//Sleep(500);
}


When the joint is deleted I get "Unhandled exception at 0x01228dfd in SimpleFlightSim.exe: 0xC0000005: Access violation writing location 0xabe8d2b7" on Root::_fireFrameEnded method.

bool Root::_fireFrameEnded(FrameEvent& evt)
{
// Remove all marked listeners
std::set<FrameListener*>::iterator i;
for (i = mRemovedFrameListeners.begin();
i != mRemovedFrameListeners.end(); i++)
{
mFrameListeners.erase(*i);
}
mRemovedFrameListeners.clear();

// Tell all listeners
bool ret = true;
for (i= mFrameListeners.begin(); i != mFrameListeners.end(); ++i)
{
if (!(*i)->frameEnded(evt)) <-- EXCEPTION
{
ret = false;
break;
}
}

// Tell buffer manager to free temp buffers used this frame
if (HardwareBufferManager::getSingletonPtr())
HardwareBufferManager::getSingleton()._releaseBufferCopies();

return ret;
}

HexiDave

13-09-2006 19:32:12

Oh, wait - you're not turning off mLaunch - are you sure it's not trying to delete it for 200 frames or something while the key is down?

if(mLaunch)
{
mAirplane->Launch();
mLaunch = false;
}


Try that instead - it looks like it correctly deletes, just that it repeatedly tries to delete it, throwing that exception. You could also do:

void Airplane::Launch()
{
if(ballJoint){
delete ballJoint;
ballJoint = 0;
}

}


Hope that works as I'm not seeing any other reason for crash...

alberts

13-09-2006 20:36:18

No, that was not the problem :( But thanks anyway :)

HexiDave

13-09-2006 22:43:16

Hmm, I don't have much experience with joints so I don't really know - memory leak maybe causing a problem? If you're not put off by sending me ,or posting here, the source code for the application, I can test it out and see if there are any memory leaks on my end or if it's just something weird happening.

Other then that, I'd say throw up the Walaber signal and hope he can rescue you :D