[Solved] Fatal exception on termination

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
lonewolff
Ogre Magi
Posts: 1207
Joined: Wed Dec 28, 2005 12:58 am
x 6

[Solved] Fatal exception on termination

Post by lonewolff »

:D :D Hi guys,

I am playing with creating materials in code. But when I close the application the program throws a an exception.

Code: Select all

MaterialPtr material = MaterialManager::getSingleton().create("Material_Test",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
ColourValue test(1.0f,0.2f,0.5f,0.5f);
material->getTechnique(0)->getPass(0)->setDiffuse(test);

Entity* temp=mSystem->o_get_by_name("sprite");
temp->setMaterialName("Material_Test");
Is there something I have to free up manually? If so how do I go about it? I have tried delete material, but that wont compile.

Thanks in advance :D
Last edited by lonewolff on Tue Nov 11, 2014 2:41 am, edited 1 time in total.
User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4304
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 135
Contact:

Re: Fatal exception on termination (shared ptr?)

Post by spacegaier »

Which Ogre version?

I assume you already ensured that it has to be related to the lines you posted, since without those the error doses not occur, right? Can you narrow it down even further? Which line is causing the crash (meaning which one do you have to comment out to get rid of the crash)?
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
User avatar
lonewolff
Ogre Magi
Posts: 1207
Joined: Wed Dec 28, 2005 12:58 am
x 6

Re: Fatal exception on termination (shared ptr?)

Post by lonewolff »

It is the last line

temp->setMaterialName("Material_Test");

Commenting it out stops the crash on exit.

The break point brings up OgreSharedPtr.h in the debugger at this line -

OGRE_FREE(pUseCount, MEMCATEGORY_GENERAL);

**Sorry - I forgot to mention it is Ogre 1.8.4
Last edited by lonewolff on Tue Nov 11, 2014 12:27 am, edited 1 time in total.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Fatal exception on termination (shared ptr?)

Post by dark_sylinc »

Your "mSystem->o_get_by_name" call looks fishy.
How are you creating the Entity.

Normally this type of crashes are because there is still a reference to the Material after shutting down.
User avatar
lonewolff
Ogre Magi
Posts: 1207
Joined: Wed Dec 28, 2005 12:58 am
x 6

Re: Fatal exception on termination (shared ptr?)

Post by lonewolff »

This is how it gets created.

Code: Select all

double ClassSystem::o_create(String name,String meshname)
{
	try
	{
		Entity *mEntity=mSceneMgr->createEntity(name,meshname);
		SceneNode *mNode=mSceneMgr->getRootSceneNode()->createChildSceneNode(name);
		mNode->attachObject(mEntity);
		mEntity->setCastShadows(false);
		return 0;
	}
	catch(Ogre::Exception ex)
	{
		return 1;
	}
}
All of that side of it is working fine. The mesh works perfectly if I use material scripts.

I only have the problem when I try to create materials programattically.

(They create and display properly on the mesh, the problem only occurs when I delete root - no problems if I don't delete root on exit)

I found this thread http://www.ogre3d.org/forums/viewtopic.php?f=2&t=70143 which suggests that you do need to clean up manualy after creating materials programatically.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Fatal exception on termination (shared ptr?)

Post by dark_sylinc »

mmmm... all looks well.

Btw, this bit of code:

Code: Select all

MaterialPtr material = MaterialManager::getSingleton().create("Material_Test",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Is this actual code? Because if "MaterialPtr material" is scoped, it should quickly decrease the reference count.
However if "material" is in a bigger scope (i.e. part of a class), it may not decrease its reference count until after the shutdown, thus causing trouble.
User avatar
lonewolff
Ogre Magi
Posts: 1207
Joined: Wed Dec 28, 2005 12:58 am
x 6

Re: Fatal exception on termination (shared ptr?)

Post by lonewolff »

dark_sylinc wrote:mmmm... all looks well.

Btw, this bit of code:

Code: Select all

MaterialPtr material = MaterialManager::getSingleton().create("Material_Test",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Is this actual code? Because if "MaterialPtr material" is scoped, it should quickly decrease the reference count.
However if "material" is in a bigger scope (i.e. part of a class), it may not decrease its reference count until after the shutdown, thus causing trouble.
Yep, that is the actual code.

It is actually created in the same scope that delete mRoot is in. Is that a problem?

[edit]
Interesting..

I surround that code block with braces to push it into its own little scope and that fixed the problem :D

You learn something every day 8)
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Fatal exception on termination (shared ptr?)

Post by dark_sylinc »

There's your problem then :)

If you don't want to scope/add braces, you can explicitly call material.setNull() (anytime before deleting root).

I'm glad this is fixed for you :)
User avatar
lonewolff
Ogre Magi
Posts: 1207
Joined: Wed Dec 28, 2005 12:58 am
x 6

Re: Fatal exception on termination (shared ptr?)

Post by lonewolff »

Thanks man :)

Been a while since I used Ogre. Loving getting back in to it again 8)
Post Reply