Strange problem deleting and recreating world

Night Elf

30-08-2007 21:10:39

I'm having a strange problem when creating an instance of World. I followed the constructor step by step and I could see the following execution:

I create a World with passing no parameters to the constructor, so it takes the default ones:
g_nxWorld = new NxOgre::World;
The constructor of World looks like this:
World::World(PhysXDriverParams driverParams) { ...etc... }
The default value for driverParams is a string, so this takes us to the followind constructor:
PhysXDriverParams(const char* p){process(p);}
Inside process(), the last line calls parse(pm), so we end up in the PhysXDriverParams::parse() method:
void PhysXDriverParams::parse(Parameters P) {
NxUnderConstruction;
...etc...
}

The definition of NxUnderConstruction is
#define NxDebug(a) NxThrow(a, 3, __FUNCTION__, __LINE__);
#define NxUnderConstruction NxDebug("This function called contains no or little code.");

The weird thing is that the first time I do new World, the code executes NxUnderConstruction without throwing any exception and continues to work as if nothing happened...

When I delete the world instance (when I exit the game to the main menu) and then create it again (starting a new game), the code reaches that line and now it does trigger an exception.

I can't make sense of what's happening. Any help, please?

betajaen

30-08-2007 21:30:06

Well for the first part, that's pretty normal. I use "new World()" all the time.

As for the second bit, NxUnderConstruction. It's just a note to me, to fill out that code, and a note to the user that function (and functions that do have NxUnderConstruction) aren't finished yet. Why it is in the PhysXParams bit after all this time, is a little odd.

As for the third bit. I have the same error, but tracing it; It crashes within the Error system (irony!) but that is due to the Error class being a singleton, and the PhysXDriver re-creating Error.

However, World isn't designed to be created twice in one sitting like that, if you want to start afresh again, all you need to do is delete all of the scenes. "mWorld->getScenes()->destroyAllOwned()".

Night Elf

30-08-2007 22:09:19

Well for the first part, that's pretty normal. I use "new World()" all the time.
This would be more of a C++ question, but why doesn't it throw the exception the first time?

However, World isn't designed to be created twice in one sitting like that
Does that mean that I should do something else to properly shut down NxOgre/PhysX?

if you want to start afresh again, all you need to do is delete all of the scenes. "mWorld->getScenes()->destroyAllOwned()".
Thanks, that worked perfectly!

betajaen

30-08-2007 22:24:10

1. Technically those aren't Exceptions, there just macros to send error messages to the log. However in fatal "exceptions" you can make the error class shutdown the application.

2. No, just delete mWorld will do. Just don't do new World; after that. You don't create Ogre Root twice do you?

3. Of course. In later versions, when the MeshManager comes around, it'll be stupid to re-new the World, else you'd have to reload those many hundreds of megabytes of collision files over again. ;)