Page 1 of 1

Big problem with engine shutdown after loading a mesh file

Posted: Fri Jul 01, 2005 10:44 pm
by cr_itm
Hello,

I have a big problem with loading a mesh (or in other words, loading is fine, but the shutdown is not).

When I use this code, everyting works fine:

Code: Select all

IAnimatedMesh* mesh = sceneManager->getMesh("model.ms3d");
IAnimatedMeshSceneNode* node = sceneManager->addAnimatedMeshSceneNode(mesh);
but the model I want to load is a static mesh, not an animated mesh. So I want to use the "addMeshSceneNode" method:

Code: Select all

IAnimatedMesh* mesh = sceneManager->getMesh("model.ms3d");
ISceneNode* node = sceneManager->addMeshSceneNode( mesh->getMesh(0) );

This way it also works - until I want to close my program/shutdown the engine. When I click on the close button of my window, the destructor calls "m_pDevice->drop();" to shutdown Irrlicht. But then (and only with the "addMeshSceneNode", not with the "addAnimatedMeshSceneNode"), Visual Studio (I use version 2003) stops and displays a message with an "Unhandled Exception at.... " (no more information). The compiler shows the file "iunknown.h" with this code:

Code: Select all

bool drop()
{
	#if defined(_DEBUG) && defined(_MSC_VER)
	if (ReferenceCounter <= 0)
		_asm int 3; // someone is doing bad reference counting.
	#endif
		--ReferenceCounter;
	if (!ReferenceCounter)
	{
		delete this;		// ***
		return true;
	}
		return false;
}
// *** This is where the compiler stops and pop up the error message (unhandled exception).

So the error must have to do with a reference counter, maybe something where the engine needs a ->drop() or something (when I don't destroy the engine/no call to device->drop()) the error doesn't appear)

Please, can anyone help? I just don't know what I'm doing wrong. Is my "addMeshSceneNode"-codeline wrong? Or must I use ->drop() on any object?


Thanks a lot for your help!

Posted: Sun Jul 03, 2005 12:23 pm
by cr_itm
Can no one help me or has an idea what the problem is?

I've tried the first Irrlicht example (HelloWorld) and changed the "addAnimatedMeshSceneNode" to "addMeshSceneNode" - when I close the example app, exactly the same error appears.

Is there no one who uses Visual Studio and may please try to change the HelloWorld example (use addMeshSceneNode) and see, if he can close the program wihtout an error?

I just can't solve the problem :-(

Even a "I tried that, and everything works fine" would help a little bit, so I know the problem is not the Irrlicht engine.


Thanks alot!

Posted: Wed Jul 06, 2005 2:34 pm
by niko
Generally, this works for me. Looks like you are doing drop() too much somehow. Diffucult to say where :)

Posted: Mon Jul 11, 2005 5:44 pm
by kingpk
try to close the device with: device->closeDevice ();
dont use drop(), bye.

Posted: Tue Jul 12, 2005 3:59 pm
by Fred
And the debugger says?

Posted: Tue Jul 12, 2005 4:04 pm
by Guest
i get this when using drop() too o.O i just tested it out, with closeDevice it does not happen ...

Posted: Sun Aug 14, 2005 5:03 am
by jerky
i have had this problem also.

here are some of the symptoms:

Code: Select all

ISceneNode* node = smgr->addMeshSceneNode(mesh->getMesh(0));
while (device->run()) {
//...
}
device->drop(); 
this gives run-time error "Unhandled Exception at.... "

however, both

Code: Select all

ISceneNode* node = smgr->addMeshSceneNode(mesh->getMesh(0));
while (device->run()) {
//...
}
smgr->clear();
device->drop(); 
and

Code: Select all

ISceneNode* node = smgr->addMeshSceneNode(mesh->getMesh(0));
while (device->run()) {
//...
}
node->remove();
device->drop(); 
do not give run-time errors.

neither does

Code: Select all

ISceneNode* node = smgr->addMeshSceneNode(mesh->getMesh(0));
while (device->run()) {
//...
}
device->closeDevice(); 
as noted above.

Must have something to do with the SceneManager not removing all of it's nodes when it's dropped by the IrrlichtDevice

Posted: Tue Aug 16, 2005 11:50 pm
by Fred
Woah steady on - compiler errors are NOT unhandled exceptions. Unhandled exceptions are runtime errors while compiler errors are compile time errors (obviously).

Sort out your errors.

Posted: Sat Aug 20, 2005 7:32 pm
by jerky
Whoops! ok, thanks.

Posted: Tue Aug 23, 2005 4:00 am
by playerdark
I have no idea if this helps you but here it goes:

If you are using DLLs or libs that rely on a different kind of memory management routine and allocate Irrlich objects there, but they are freed in the irrlicht engine, it is possible that the free() / delete routine of the other memory management was used. I had that happen since I am using my own memory management which is based on MFC's new/delete overload.

My solution was to add destroy() functions to the Irrlich DLL for objects that were created within Irrlicht. If you are using MFC debug memory management it might also be the case for you, not sure, just an idea where to poke.

A sidenote to Niko: I realise that some destroy() function that are still in the documentation are no longer in the code. In general I think a module intern destroy() as an option is a good idea, for the situation described above