Exception in attachObject()

lexex

25-01-2007 14:59:22

Hi,

I have looked at the demos, but was not able to reproduce OgreOde bodies and geometries. I always get the same exception:

Object already attached to a sceneNode or a Bone.

Even when using this sample code:


// Create the Ogre box
String name = String("Box_") + StringConverter::toString(i);
Entity* box = _mgr->createEntity(name,"crate.mesh");
box->setCastShadows(true);

SceneNode* node = _mgr->getRootSceneNode()->createChildSceneNode(name);
node->attachObject(box);
node->setScale(0.1,0.1,0.1);

// Set the position and rotate that, then rotate the box by the same amount
Quaternion q;
q.FromAngleAxis(Degree(45),Vector3::UNIT_Y);
Vector3 pos(x,y + 0.5,-10.0);
node->setPosition(q * pos);
node->setOrientation(q);

// Create a box for ODE and attach it to the Ogre version
OgreOde::Body* body = new OgreOde::Body();
node->attachObject(body);
body->setMass(OgreOde::BoxMass(0.01,Vector3(1,1,1)));

OgreOde::BoxGeometry* geom = new OgreOde::BoxGeometry(Vector3(1.0,1.0,1.0),_space);
geom->setBody(body);


The exception is thrown while trying to attachbody to node. I already looked into the code of attachObject and yes body isAttached is true. But why? Please, has anybody seen this before and is able to help me?

gugus

25-01-2007 17:37:15

yes i have ever saw it.That's why i use codee:block now.I didn't arrive to fix it.

lexex

25-01-2007 17:49:48

Hi gugus,

sorry I am confused. code:blocks is an IDE so how did it solve this problem...

gugus

25-01-2007 17:54:05

Yes because i change compiler too.