[Solved] Problem with custom code with character class

mnm23

17-08-2006 18:46:01

Hey guys. Im having a problem with the character class. Everything compiles fine. When i try to run the exe it crashes. The crash points to the character class in nxOgre saying there is nothing pointing there. It comes back with a NULL pointer at

mNode = owner->mSceneMgr->getRootSceneNode()->createChildSceneNode(mName);

mNode is 0 and owner is 0.

In my code i have it set up like this.

PlayerState::PlayerState(nxOgre::character *mChar, Ogre::SceneManager *sm, Ogre::SceneNode *sn, char *name, char *meshName, Ogre::Vector3 size)
: mCharNode(mChar), mName(name)
{
mAb = 0;

//this->mCharNode = mChar;

GameInfo::getInstance()->addPlayer(name, this);

bp.setToDefault();
bp.setGravity(true);
bp.setSlopeLimit(45);
bp.setStep(0.5);
bp.setShapeAsCapsule(40, 150);
bp.setMesh("");

if(!mChar)
myNamespace::writeF("GameInit.log","no nxOgre Character");
if(!sm)
myNamespace::writeF("GameInit.log","no sceneManager");

this->mCharNode = bp.create("myCharacter", Ogre::Vector3(6000, 1000, -500), mScene);

this->mEntity = sm->createEntity(mName, meshName);
this->mEntity->setNormaliseNormals(true);

if(!sn)
{
this->mSceneNode = mChar->mNode->createChildSceneNode(mName);

}
else
{
this->mSceneNode = sn->createChildSceneNode(name);
}

this->mSceneNode->attachObject(mEntity);
this->mSceneNode->setScale(size);

}



I call PlayerState in my LevelState like this.

roman = new PlayerState(romanChar, mSceneMgr, romanNode, "Roman", "RomanBoss3.mesh", Vector3(1, 1, 1));


I have used this style many times before and it works fine, but with recent events with nxOgre not liking the way i do things i thought it would be good to ask in here why this cant be done.

betajaen

17-08-2006 19:34:16

How on earth can you cast a character into a SceneNode they are totally unrelated, infact how on Earth will your compiler allow it?

Also the idea of setMesh is to put your mesh in for you automatically; not to create it a few lines later.

mnm23

17-08-2006 19:44:12

How is what i have there any different than

ninjaNode = myNinja->mNode->createChildSceneNode();


where ninjaNode is the sceneNode and myNinja is nxOgre::character

in the code i had writen in first post

mCharNode and mChar are both nxOgre::character.

So how does the above liine of code differ from.

this->mSceneNode = mChar->mNode->createChildSceneNode(mName);


Is this the line you were talking about.

betajaen

17-08-2006 19:50:34

this->mCharNode = bp.create("myCharacter", Ogre::Vector3(6000, 1000, -500), mScene);

This one, is mCharNode an Ogre SceneNode or not?

mnm23

17-08-2006 19:53:07

Sorry for the way they were titled. mCharNode is nxOgre::character

mCharacter was taken (LOL)

betajaen

17-08-2006 19:56:36

The only things I can think is that either the scenenode "myCharacter" already exists, or mScene is passed on as null.

mnm23

17-08-2006 20:07:36

betajean you kick ass. You were right about mScene. I had to change the constructor to this.

PlayerState::PlayerState(nxOgre::character *mChar, nxOgre::scene *scen, Ogre::SceneManager *sm, Ogre::SceneNode *sn, char *name, char *meshName, Ogre::Vector3 size)
: mCharNode(mChar), mScene(scen), mName(name)


Because mScene doesnt actually create anything untill level state it had no idea what this was hence the reason for NULL pointer. Thanks a lot.

betajaen

17-08-2006 20:10:21

Good job. I've marked the title of this thread with something less misleading ;)

mnm23

17-08-2006 20:20:28

LOL thanks again