0.9] nxogre::body error when my gamestate change state!!!!

Felipe

23-08-2007 11:51:29

the error happen when change of state

my code:

#include "PlayState.h"
#include "PauseState.h"
#include "MainMenuState.h"
#include <OgreFrameListener.h>
#include <OgreEntity.h>
#include <OgreMeshManager.h>

#include "WorldManager.h"
#include "NxOgre.h"

using namespace NxOgre;
using namespace Ogre;


PlayState* PlayState::mPlayState;

void PlayState::enter( void )
{
mRoot = Root::getSingletonPtr();
mSceneMgr = mRoot->getSceneManager( "TerrainSceneManager" );
mCamera = mSceneMgr->createCamera( "Camera" );
mCamera->setNearClipDistance( 1 );
mCamera->setFarClipDistance(0);
mViewport = mRoot->getAutoCreatedWindow()->addViewport( mCamera );

mWorld = new World("log: html");
mScene = mWorld->createScene("Main", mSceneMgr, "gravity: yes, floor: yes");

Ogre::StaticGeometry *mStaticGeom= mSceneMgr->createStaticGeometry("Grid");
mStaticGeom->addEntity(mSceneMgr->createEntity("nx.floor", "nx.floor.mesh"), Ogre::Vector3(0,-0.05f,0));
mStaticGeom->build();
mStaticGeom->setCastShadows(false);

mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
mBody = mScene->createBody("cube.1m.mesh", new CubeShape(1), Vector3(0,5,0), "mass: 10");



}

void PlayState::exit( void ) {

mSceneMgr->clearScene();
mSceneMgr->destroyAllCameras();
mRoot->getAutoCreatedWindow()->removeAllViewports();

//delete mBody;
delete mWorld;
}



the error in line : Ogre::SceneNode::ObjectIterator object_it = mNode->getAttachedObjectIterator();

Body::~Body() {

if (mNode == 0)
return;

// here the error
Ogre::SceneNode::ObjectIterator object_it = mNode->getAttachedObjectIterator();
Ogre::MovableObject *m;
while(object_it.hasMoreElements()) {
m = object_it.getNext();
if (m->getMovableType() == "Entity") {
mOwner->getSceneManager()->destroyEntity((Ogre::Entity*) m);
}
else {
mNode->detachObject(m);
mOwner->getSceneManager()->getRootSceneNode()->attachObject(m);
}
}

betajaen

23-08-2007 12:08:33

I suspect the entity in mNode has been deleted but not unattached.

It may be these lines:

mSceneMgr->clearScene();
mSceneMgr->destroyAllCameras();

Felipe

23-08-2007 12:22:27

i make this, and the error continue

void PlayState::exit( void )
{

mSceneMgr->clearScene();
mSceneMgr->destroyAllCameras();
mRoot->getAutoCreatedWindow()->removeAllViewports();

delete mWorld;
}

betajaen

23-08-2007 13:09:27

Will you be reusing NxOgre again in the next state? Treat mWorld as a singleton, and just destroy the Scene:


mWorld->destroyScene(mScene->getName());
mSceneMgr->clearScene();
mSceneMgr->destroyAllCameras();
mRoot->getAutoCreatedWindow()->removeAllViewports();



Then before you delete mRoot, delete mWorld.

Felipe

23-08-2007 13:56:41

how i Treat mWorld as a singleton?

betajaen

23-08-2007 14:14:32

You don't, Just create it and delete it once - and don't treat it as a disposable object.

Felipe

23-08-2007 14:33:53

you have a sugestion

i create and instance NxOgre::World in my gamemanager

how can i get it;

NxOgre::World haven't getSingletonPtr();

betajaen

23-08-2007 14:49:52

I know. All I'm saying is with your game state code; Delete the scene not the world. Only delete the world when your absolutely sure your not going to use it any more, like Ogre's Root.