crash when i call createBody

unclepauly

31-08-2008 18:46:20

ive just downloaded the latest NxOgre, and this is my first time of using it.

i have used flour (just downloaded the one from the web site) to convert box.mesh (the 2k one that comes with Ogre) into box.nxs, and now all i want to do is call createBody on it. heres my code:


NxOgre::Resources::ResourceSystem::getSingleton()->addMeshAs("file://D:\\GAME_STUFF\\FYP\\theGame\\media\\models\\box.nxs", "mybox");

NxOgre::Convex* convex = new NxOgre::Convex(NxOgre::Resources::ResourceSystem::getSingleton()->getMesh("mybox"));

NxOgre::CompoundShape* shape = new NxOgre::CompoundShape();
shape->add(convex);

NxOgre::Body* myboxbody= mNxScene->createBody("my_box_body", shape, Ogre::Vector3(360, 50, 360), "model: box.mesh", "mass: 10");


the app crashes at createBody with an access violation.

the debugger shows that after i new the Convex with getMesh("mybox"):

- convex is a valid pointer
- convex->mMesh is also a valid pointer, but every member of mMesh (mTriangleMesh, mConvexMesh) is uninitialised (0xcdcdcdcd).
- convex->mShapeDescription.type is NX_SHAPE_CONVEX, but
- convex->mShapeDescription.meshData is NULL

is any of the above the reason for the crash, and if so what am i doing wrong ?

mcaden

31-08-2008 18:56:35

I believe there was a bugging specific to convex meshes. It's in one of the sticky threads.

haha~~ Guess What? I've found the root cause of this annoying bug!
Now here is my fix.
At the bottom of the method in NxOgreMesh.cpp :

void Mesh::MeshData::zero() {
mTriangleMesh = 0;
mConvexMesh = 0;
mSkeletonMesh = 0;
mClothMesh = 0;
mSoftBodyMesh = 0;
mType = MT_Unknown;
mNbReferences = 0;
}

Append this line:

mMaterialAlias = 0;


Because isZero() method checks the variable mMaterialAlias whether it's initialized.


bool Mesh::MeshData::isZero() const {
return (mTriangleMesh == 0 && mConvexMesh == 0 && mSkeletonMesh == 0 && mClothMesh == 0 && mSoftBodyMesh == 0 && mMaterialAlias == 0);
}


Besides, it's necessary to add mMesh.zero() before loading in the constructor:

Mesh::Mesh(const ResourceIdentifier& ri) {
mMesh.zero();
load(ri);
}

/////////////////////////////////////////////////////////////

Mesh::Mesh(Resource* rs) {
mMesh.zero();
load(rs);
}


So that I can use converted files from Flour now. Cheers!


Do that then rebuild. Might fix it.


Sidenote though - why are you using CompoundShape there? No need for it unless you're actually going to use a CompundShape. You've just got a convex, so use Convex.

Otherwise things look good. You might check ogre.log for any exceptions thrown there. It might be having trouble finding the mesh on that path for some reason.

unclepauly

31-08-2008 19:03:58

yes you are right, that has done the job!

although im surprised this fix hasn't been made permanent if its a well known bug.

anyway good man, all good now, thank you.

betajaen

31-08-2008 19:24:34

It's in the NxOgre source and will be released within the week - when I finish IceCream and implement it into Cake.

mcaden

01-09-2008 04:11:54

Ice cream and cake...woot!