[Solved] OGRE3DBody Crash on update

danoli3

06-10-2009 16:25:16

Hey,

We are currently having a crash for any player that is online after a player leaves the game,

NxOgre Revision ( current 7/10/09 http://github.com/betajaen/nxogre )
Ogre 1.6.3

Here is the stack:

Player.exe!OGRE3DBody::advance(float __formal=0.023000000, float __formal=0.023000000) Line 124 + 0x51 bytes C++
NxOgre_Debug.dll!NxOgre::TimeController::_literal(float user_deltaTime=0.023000000) Line 115 + 0x25 bytes C++
NxOgre_Debug.dll!NxOgre::TimeController::advance(float deltaTime=0.023000000) Line 70 + 0x14 bytes C++
Player.exe!WorldState::update(float deltaTimeSecs=0.018999999) Line 213 + 0x18 bytes C++
Player.exe!Application::update() Line 96 + 0x1e bytes C++
Player.exe!main() Line 12 + 0x1e bytes C++
Player.exe!__tmainCRTStartup() Line 586 + 0x19 bytes C
Player.exe!mainCRTStartup() Line 403 C



Extra Information:
For our world(WorldState) when a player joins it creates an actor.
In our actor on initialisation we create our OGRE3DBody:

Header
// NxOgre Actor Body
OGRE3DBody* physicsBody;)


Source:
NxOgre::RigidBodyDescription desc;
desc.mBodyFlags |= NxOgre::Enums::BodyFlags_FreezeRotation;
desc.mMass = 0.5f;
desc.mMaxAngularVelocity = 5;

// init the physics body using the scene node
physicsBody = renderSystem->createBody( new NxOgre::Capsule( 5, 20 ), NxOgre::Functions::XYZ<Ogre::Vector3, NxOgre::Vec3>(position), baseNode, desc );


When any player leaves the onPlayerExit function is called and removes that player(actor) from the game.
This is in WorldState:
Source:
std::map<unsigned short, Actor*>::iterator i = actors.find(playerNetID);

if (i != actors.end())
{
// Remove the actor for the player that has just exited
Actor* actor = (*i).second;
chatConsole->addText("'" + actor->getTitle() + "' has left the world.");

delete actor;
actors.erase(i);

this->updatePlayerList();
}


The crash starts (as you can see above in the stack) when the advance is called for the Physics.
pTimeController->advance( NxOgre::Real( nxOgreTimer ));

It tries to set the position of the OGRE3DBody that now doesn't exist and hence the crash.

Any work arounds? or fixes?

Thanks ;)

-Danoli3

spacegaier

06-10-2009 16:31:46

You can't just delete the Actor. Use this method instead to properly get rid of the whole OGRE3DBody (so the Actor and its visualization):
mRenderSystem->destroyBody(m_physicsBody);

danoli3

06-10-2009 16:43:29

You can't just delete the Actor. Use this method instead to properly get rid of the whole OGRE3DBody (so the Actor and its visualization):
mRenderSystem->destroyBody(m_physicsBody);


Worked! :D!

Thanks so much