NxOgre Access Violation [0.9]

mgoodman

19-05-2008 20:52:54

Dear physics master,

So I'm slowly trying to integrate NxOgre into the project we're working on. I tried to include a NxOgre::World into our project. It compiles fine, but I always get an Access Violation when it runs. Here are the rough details:
- Ogre 1.4.7, NxOgre 0.9-38, Visual Studio 2008 (Debug Mode, not Release), Microsoft Windows Vista.
- GameRoot class extends Ogre::Root and GameWorld class extends NxOgre::World. Here's a small piece of our UML diagram to help you understand.


- The GameWorld constructor is basically a copy of the NxOgre::World constructor, except mRoot is defined as our GameRoot and I had to comment out the if statements at the end since GameWorld is not a friend class of the appropriate classes.

GameWorld::GameWorld( PhysXDriverParams driverParams )
{
mRoot = GameRoot::getSingletonPtr();
mDriver = new PhysXDriver(this, driverParams);

srand((unsigned)time(0));

mDriver->getSDK()->setParameter(NX_VISUALIZATION_SCALE, 1.0f);
mDriver->getSDK()->setParameter(NX_SKIN_WIDTH,0.01f);
mDriver->getSDK()->setParameter(NX_VISUALIZE_WORLD_AXES, true);
mDriver->getSDK()->setParameter(NX_CONTINUOUS_CD, true);
mDriver->getSDK()->setParameter(NX_CCD_EPSILON, 0.01);

/*#if (NX_USE_CHARACTER_API == 1)
mCharacterController = new CharacterController();
#endif

#if (NX_USE_DEBUG_RENDERER_API == 1)
mDebugRenderer = 0;
#endif*/
}


- Here's what the CoreApplication class does at first:

bool CoreApplication::SetupApplication()
{
CreateGameRoot(); //creates a new GameRoot
SetupResources(); //config file parsing, resourceGroup creation, etc.
CreateGameWorld(); //creates a new GameWorld
(...)
}


- The program compiles fine, but I get the following Access Violation when I run it:

Unhandled exception at 0x0157d0e6 (NxOgre_d.dll) in planet2.exe: 0xC0000005: Access violation reading location 0xcdcdcde9.


- Cue sexy (not really) Visual Studio 2008 debug screenshot!


So I hope that gives you a good idea of the problem. I tried passing different PhysXParams to the GameWorld constructor (like "time-controller:ogre" or just "") and I get the same Access Violation regardless. I'd appreciate any help you can offer.

Thanks,
Mathieu

betajaen

19-05-2008 23:19:25

That is an interesting approach, I've never sub-classed World before. I am surprised it would crash like that; null GameWorld pointer perhaps? But instead of duplicating the constructor have to tried this?

GameWorld::GameWorld(PhysXDriverParams driverParams) : NxOgre::World(driverParams)
{
// No code!!
}


If that doesn't work, which there is no reason why it shouldn't. You'll have to use World normally like the rest of us.


Also, I love the new nickname.

mgoodman

19-05-2008 23:45:57

Thanks for the quick response, sensei. Clearing the GameWorld constructor and inheriting the NxOgre::World constructor as you suggested did indeed fix the problem.

Problem is, the way it is now, our GameWorld is using a regular Ogre::Root instead of our personal GameRoot (which extends Ogre::Root). We need to override a few things in Ogre::Root so there's no way around it.

I will play around with it and let you know what I find out.

betajaen

19-05-2008 23:50:28

You could set "mRoot" to your game root within the GameWorld constructor; it's hacky but it may work.

mgoodman

19-05-2008 23:52:17

You could set "mRoot" to your game root within the GameWorld constructor; it's hacky but it may work.

Isn't that was I was doing originally? Check the code in my original post.

betajaen

20-05-2008 00:08:38

No, I meant like this:

GameWorld::GameWorld(PhysXDriverParams driverParams) : NxOgre::World(driverParams)
{
mRoot = GameRoot::getSingletonPtr();
}

mgoodman

20-05-2008 01:12:47

Dear Gravity Lord,

I am an idiot. For some reason I thought that when overriding the NxOgre::World constructor as you suggested, that the code in my GameWorld constructor would be executed BEFORE the parent constructor, which of course isn't the case. If it was, NxOgre::World's constructor would have just overrided the mRoot member, which is why I had just copied the entire constuctor instead.

I did what you suggested and our code now compiles and executes correctly. Of course, this is just the first step... now I need to integrate Actors into this mess.

Thanks a bunch! Can't wait to show (off) something functional.

P.S. I blame my programming background: 7 years of Java and 0 years of C++.

betajaen

20-05-2008 10:34:31

P.S. I blame my programming background: 7 years of Java and 0 years of C++.

My sympathies. I hate Java with a fiery passion, it's also the reason why I learned OO so late in my programming "lifestyle".