Dynamic body removal

chuck

12-07-2006 10:32:03

I was wondering if there is any way too dynamically remove a body and any collision data associated with it from the world (and destroy it) at run time. The reason is that I've got a massive world (that uses PLSM2) and don't want to have any more static geometry loaded at anyone time than is necessary to conserve memory usage etc.

walaber

12-07-2006 10:51:18

just delete the body object, and the collision object if you haven't already.

josedagardner

13-07-2006 07:51:09

I'm having a problem deleting a body. I have a missile that I want to disappear on impact, so I'm calling delete on it. Being new to Ogre I'm probably just doing something stupid.

I get this error after it's deleted:
Unhandled exception at 0xfeeefeee in HellaRacing.exe: 0xC0000005: Access violation reading location 0xfeeefeee.

This occurs in the newtonTransformCallback in ogrenewt_body.cpp:

if (me->m_transformcallback)
me->m_transformcallback( me, orient, pos );

all the body data in me is set to 0xfeeefeee (since I just deleted it), but this callback shouldn't be getting called if the body is deleted? Here is where I delete it:

int ProjectileMatCallback::userProcess()
{
Body* proj;
if (m_body0->getType() == BT_PROJECTILE && m_body1->getType() == BT_TERRAIN)
{
proj = m_body0;
}
else if (m_body1->getType() == BT_PROJECTILE && m_body0->getType() == BT_TERRAIN)
{
proj = m_body1;
}
if(proj)
{
delete proj;
}

What am I doing wrong?

walaber

14-07-2006 08:10:39

you can't delete the body from inside a collision callback, because Newton is in the middle of it's internal loop there. it doesn't "realize" that the body has been deleted, and tries to access it later.

you should mark a flag, and delete the body after the call to World::update() has completed.

josedagardner

14-07-2006 09:29:23

That makes a lot of sense. Thanks.

chuck

14-07-2006 10:55:25

Thanx, just what I wanted.