[BloodyMess] nxs file and kinematic body problem

ironwolf151

01-06-2009 19:38:26

Hi,

There is something i don't understand.
I'm trying to use .nxs for my game collisions and not .mesh

But i have a problem.
This is my function to create a kinematic body with an nxs file:

OGRE3DKinematicBody *Physic::test(NxOgre::ArchiveResourceIdentifier archive, Ogre::String mesh, int x, int z)
{
OGRE3DKinematicBody *object;

NxOgre::Mesh *nxs_object = NxOgre::MeshManager::getSingleton()->load(archive);
object = this->_RenderSystem->createKinematicBody(new NxOgre_Namespace::Convex(nxs_object), NxOgre_Namespace::Real3(x, 20, z), mesh);

return object;
}


And the problem is here.
If i call it only one time there are no problems.
But when i call it two times or more i obtain an error when i leave my game.
I call it like that :

this->ground = this->_Physic->test("media:Ground.nxs", "Ground.mesh", (((this->_line) / 2) * 10) + 5, (((this->_column - 1) / 2) * 10) + 4);

this->wall = this->_Physic->test("media:Wall_UD.nxs", "Wall_UD.mesh", ((this->_column * 10) / 2), ((this->_line) * 10) - 5);


And when i do that , i obtain this error :
Instruction at "0x00d0affa" use memory adress "0x7851cc04". Memory can't be read. Clic ok to leave the program.


Why i obtain this error if i call my function more than one time ?

Thanks

betajaen

01-06-2009 20:01:52

Very strange.

Are you loading ground.nxs and Wall_UD.nxs multiple times? Because you shouldn't because they can be shared between shapes.

ironwolf151

01-06-2009 20:05:35

No , i load Ground.nxs and Wall_UD.nxs only one time.
I don't need to load them many time ? so how i can use a Kinematic body i have loaded at many places in the same time ?

edit : okay i found the error ... indeed i didn't load many time the nxs file. But the mesh file was loaded 2 times , that's why i had this error at the end.
But i don't see how to use the kinematic body i have created at many places at the same time.

betajaen

01-06-2009 20:25:49

Pre-load your meshes, then keep them in stl map. Then you can just give it to each kinematic body when you need to.

ironwolf151

01-06-2009 20:44:48

So if i understand i should do this at the begining to pre-load them :

this->ground = NxOgre::MeshManager::getSingleton()->load("media:Ground.nxs");
this->wall_ud = NxOgre::MeshManager::getSingleton()->load("media:Wall_UD.nxs");


And after when i want to use them i do this for example :

OGRE3DKinematicBody *object;
object = this->_RenderSystem->createKinematicBody(new NxOgre::Convex(this->wall_ud), NxOgre::Real3(x, 20, z), "wall_ud.mesh");


But if i do that , if i tried to create two kinematic body which use this->wall_ud and wall_ud.mesh but not a the same position the program crash before to display anything.
So i think i didn't understand something , but i don't see what :s i'm sorry :s

ironwolf151

01-06-2009 23:40:54

I don't see what's the problem ...

I have this in my constructor class :

NxOgre::ResourceSystem::getSingleton()->openArchive("media", "file:media/levels/level1");
this->ground = NxOgre::MeshManager::getSingleton()->load("media:Ground.nxs");
this->wall_ud = NxOgre::MeshManager::getSingleton()->load("media:Wall_UD.nxs");


And after , i do this :

// Create the ground
this->_RenderSystem->createKinematicBody(new NxOgre::Convex(this->ground), NxOgre::Real3(0, 20, 0), "Ground.mesh");

// Create 2 wall with the same mesh but not a the same position
this->_RenderSystem->createKinematicBody(new NxOgre::Convex(this->_wall_ud), NxOgre::Real3(0, 20, 0), "Wall_UD.mesh");
this->_RenderSystem->createKinematicBody(new NxOgre::Convex(this->_wall_ud), NxOgre::Real3(100, 20, 100), "Wall_UD.mesh");


So i pre-loaded my meshes , no ?
With this code my program crash at the begining , why ?
What's wrong in my code ?


Thanks

betajaen

02-06-2009 00:27:56

Your first snippet of code is AFTER the World class was created?

ironwolf151

02-06-2009 00:29:41

Yes it's after : NxOgre::World::createWorld();

Why ?

ironwolf151

02-06-2009 19:18:05

Nobody knows where is the problem ? :?

spacegaier

02-06-2009 19:54:20

With this code my program crash at the begining
Where excactly?

Yes it's after : NxOgre::World::createWorld();

Why ?

Otherwise there would probably be invalid pointers (Scene, RenderSystem, ...), I guess.

Ogre.log is okay (or is it an Ogre in the end)?

ironwolf151

03-06-2009 00:04:11

Okay , i'm sorry the program didn't crash at the begin , in reality it crashes when i leave it.
I obtain the same error that the begin.

I obtain this : Instruction at "0x00d0affa" use memory adress "0x7851cc04". Memory can't be read. Clic ok to leave the program.

But now i don't load my nxs files many times , i load them only one time.
This is my constructor , where we can see my NxOgre initalisation and my nxs file loading.

this->_NxWorld = NxOgre::World::createWorld();
this->_VisualDebugger = this->_NxWorld->getVisualDebugger();

this->_NxSceneDesc.mGravity = NxOgre::Real3(0, -9.8f, 0);
this->_NxSceneDesc.mName = "Ball escape scene";
this->_NxScene = this->_NxWorld->createScene(this->_NxSceneDesc);

this->_NxScene->getMaterial(0)->setStaticFriction(0.5);
this->_NxScene->getMaterial(0)->setDynamicFriction(0.5);
this->_NxScene->getMaterial(0)->setRestitution(0.1);

this->_RenderSystem = new OGRE3DRenderSystem(this->_NxScene);
this->_TimeController = NxOgre::TimeController::getSingleton();

NxOgre::ResourceSystem::getSingleton()->openArchive("media", "file:media/levels/level1");
this->ground = NxOgre::MeshManager::getSingleton()->load("media:Ground.nxs");
this->wall_ud = NxOgre::MeshManager::getSingleton()->load("media:Wall_UD.nxs");

if (DEBUG)
{
this->_VisualDebuggerRenderable = new OGRE3DRenderable(NxOgre::Enums::RenderableType_VisualDebugger);
this->_VisualDebugger->setRenderable(this->_VisualDebuggerRenderable);
this->_VisualDebuggerNode = this->_Mgr->getRootSceneNode()->createChildSceneNode();
this->_VisualDebuggerNode->attachObject(this->_VisualDebuggerRenderable);
this->_VisualDebugger->setVisualisationMode(NxOgre::Enums::VisualDebugger_ShowAll);
}

this->_Ball = createPhysicEntity(new NxOgre::Sphere(2), NxOgre::Real3(10, 44, 10), "Sphere01.mesh", "Examples/vent", 2);


And after i try to create two kinematicbody with the same nxs file i loaded before , and the same .mesh

this->_RenderSystem->createKinematicBody(new NxOgre::Convex(this->wall_ud), NxOgre::Real3(0, 20, 0), "Wall_UD.mesh");
this->_RenderSystem->createKinematicBody(new NxOgre::Convex(this->wall_ud), NxOgre::Real3(100, 20, 100), "Wall_UD.mesh");

It work , but i obtain the error i said when i leave my program.

Has someone an idea ? :s

ironwolf151

03-06-2009 00:19:15

mmhhh ... it works now , but i don't understand why.

I just changed in my code a little things :
when i posted because of the error , i had load only one mesh with the xns file method , the other object was loaded like i did before ( i created a kiematicbody with a .mesh and not a .nxs ).
So i had .nxs and .mesh in my code.


Now it works because all my objects are loaded with nxs file , there are no more kniematibody with .mesh , only .nxs

Isn't it possible to have twice ?

betajaen

03-06-2009 10:23:49

I can tell you that PhysX can use many convex shapes can share the same convex mesh, and my copy of NxOgre 1.5.5 can do so as well (see the below picture). 28 regular bodies and 2 kinematic bodies all using the same "barrel.nxs" mesh. It may be differences between the two versions, but I doubt it. This is my code to compare with yours;

ResourceSystem::getSingleton()->openArchive("media", "file:.");

NxOgre::Mesh* mesh = NxOgre::MeshManager::getSingleton()->load("media:barrel.nxs");
for (unsigned int i=0;i < 28;i++)
mRenderSystem->createBody(new NxOgre::Convex(mesh), Vec3(i, 1, 0), "barrel.mesh");

mRenderSystem->createKinematicBody(new NxOgre::Convex(mesh), Vec3(0, y, 0), "barrel.mesh");
mRenderSystem->createKinematicBody(new NxOgre::Convex(mesh), Vec3(4, y, 0), "barrel.mesh");

ironwolf151

03-06-2009 15:28:00

Yes , i do it like that now , that's why it works.
But i woulds like to say , that in my last code i used the two methods at the same time , but not with the same mesh , like that :

mRenderSystem->createKinematicBody(new NxOgre::Convex(mesh), Vec3(0, y, 0), "barrel.mesh");
mRenderSystem->createKinematicBody(new NxOgre::Box(10, 10, 10), Vec3(0, y, 0), "barrel.mesh");


And with that , i had an error when i left the program.