delete scene; -> unhandled exception

SONB

06-08-2006 13:24:53

Hi all!

I'm trying to impliment nxOgre into my project. I'm on tutorial 1 right now. My problem occurs on deleting the scene. This is the error message:

Unhandled exception at 0x7c812a23 in Black Rain.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012f1b4..

My code:
{
ogre = new Ogre::Root("", "");
...
sceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC);
...
world = new nxOgre::world(ogre, sceneMgr);
scene = world->createScene("Main", sceneMgr);
...
// GAME LOOP
...
// END GAME LOOP

delete scene;
delete world;
delete ogre;
}


The debugger stops in the following function in new.cpp:
void *__CRTDECL operator new(size_t size) _THROW1(_STD bad_alloc)
{ // try to allocate size bytes
void *p;
while ((p = malloc(size)) == 0)
if (_callnewh(size) == 0)
{ // report no memory
static const std::bad_alloc nomem;
--> _RAISE(nomem);
}

return (p);
}


If I delete delete scene; ogre.log reports a memory leak.

My application was built in release mode.
I don't know why, but in debug mode the debugger asks me for ogremain.dll and not for ogremain_d.dll...

I'm using:
nxOgre CVS
PhysX 2.4.4
VS 2005

Can anyone help me? betajaen? :(
Thanx a lot in advance!

::SONB::

SONB

06-08-2006 14:48:57

Hmm.. well, I found a strange solution to my problem. I changed the way I create the scene:

From:
scene = world->createScene("Main", sceneMgr);

To:
scene = new nxOgre::scene("Main", world, sceneMgr);

It works fine now.

There is another problem. I'd like to build my application in debug mode to check the ogreleaks.log. But, as I said before, the debugger asks for ogremain.dll (the release version), and if I copy the dll into my debug directory it gives me an error:

Unhandled exception at 0x011c07c0 (OgreMain.dll) in Black Rain.exe: 0xC0000005: Access violation reading location 0x0000000c.

and stops in the function:
void LogManager::logMessage( const String& message, LogMessageLevel lml, bool maskDebug)
{
--> if (mDefaultLog)
{
mDefaultLog->logMessage(message, lml, maskDebug);
}
}
in ogrelogmanager.cpp

betajaen

06-08-2006 16:59:42

I believe the reason why it's crashing is because, your deleting scene. The solution is to don't delete it, and create it via world.

World cleans up when it's deleted anyway, like how Ogre does it.

As for debugging; If you manage to overcome that error, Debug mode will completely fail when it meets the memory manager or PhysX what ever comes first!

Also; Are you using the variable name "world" for the world class, same with "scene" for scene. Because I'm pretty sure you can't do that in C++?

SONB

06-08-2006 17:31:10

Thank you for your answer, betajaen!

I changed the variable names. Now the scene is created via world and I don't delete it myself.

And it works fine :D .

But do I understand it right that I should always compile my project in release mode? If so, how should I trace memory leaks? You know, the ogreleaks.log.


Anyway thanx a lot for your advices!

betajaen

06-08-2006 18:55:39

But do I understand it right that I should always compile my project in release mode? If so, how should I trace memory leaks? You know, the ogreleaks.log.

Sadly you can't. PhysX and the memory manager used with PhysX and NxOgre (that handles collision model generation for meshShapes and convexShapes) refuses to work in Debug mode, it crashes a lot. I have been trying to fix it on and off for the last few months with no avail.

But don't worry, NxOgre is quite tidy and tends to clean up after itself when it's finish playing :D

magura

07-08-2006 03:16:44

it just means that you will have to monitor your own memory leaks.

I've just started with the boost library, which you may find useful if you havent used it already.

It makes an important distinction between scoped_ptrs and shared_pts (variables that you will reference throughout the application, such as your own objects).

shared_ptr's work through a reference count, so you can be pretty blaize with them, compared to raw pointers.

SONB

13-08-2006 13:10:13

Hi magura!

Where can I get the boost library?



::SONB::

betajaen

13-08-2006 14:11:11

Erm, boost.org?

SONB

13-08-2006 16:28:02

Oh.. thanx betajaen!

I'm new to boost.. :oops:



::SONB::