Problem with creating a material

maaschn

05-02-2012 18:44:49

Hello Community,

I am a newbie with mogre and I am trying to apply an own material to my ManualObject which I create in form of a trianglist from a stl-File.

I found code which i inserted in my project:

MaterialPtr moMaterial = MaterialManager.Singleton.Create("line_material", "debugger");
moMaterial.ReceiveShadows = false;
moMaterial.GetTechnique(0).SetLightingEnabled(true);
moMaterial.GetTechnique(0).GetPass(0).SetDiffuse(0, 0, 1, 0);
moMaterial.GetTechnique(0).GetPass(0).SetAmbient(0, 0, 1);
moMaterial.GetTechnique(0).GetPass(0).SetSelfIllumination(0, 0, 1);
moMaterial.Dispose();


When i compile my project in VS 2010 it crashes at the first line where the Material is created. The program says

"An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in Mogre.dll

Additional information: External component has thrown an exception."

The scenemanager is initialised before, the root node is created, the Resources are defined and initialised and the renderWindow and Render System are created

I hope anybody can help me


Thanks maaschn

smiley80

06-02-2012 08:16:10

Check 'Ogre.log' for errors.
I guess you don't create the 'debugger' resource group:
ResourceGroupManager.Singleton.CreateResourceGroup("debugger");

maaschn

06-02-2012 08:44:02

Thanks so much. That was the correct guess.

zarfius

06-02-2012 10:55:50

An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in Mogre.dll
It's also a good idea to wrap your code in a try catch block, but you need to handle SEHExceptions as a special case. Something like this:


try
{
// your Mogre code that might throw an exception
}
catch (SEHException ex)
{
if (OgreException.IsThrown)
MessageBox.Show(OgreException.LastException.Description);
else
MessageBox.Show(ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

Pyritie

08-02-2012 17:52:53

An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in Mogre.dll
It's also a good idea to wrap your code in a try catch block, but you need to handle SEHExceptions as a special case. Something like this:


try
{
// your Mogre code that might throw an exception
}
catch (SEHException ex)
{
if (OgreException.IsThrown)
MessageBox.Show(OgreException.LastException.Description);
else
MessageBox.Show(ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

Sometimes if one of my shaders throws an error (it doesn't crash ogre), and later on I get a different, completely unrelated error, the message box shows the old shader error instead of the message I actually care about. It gets annoying but I haven't really found much of a workaround yet.

Beauty

11-04-2012 13:03:50

MaterialPtr moMaterial = MaterialManager.Singleton.Create("line_material", "debugger");
You use my code for 3D lines, which I published in the wiki. :D

it crashes at the first line where the Material is created

Reason:
In Ogre/Mogre 1.6 the resource groups were created automatically.
In Ogre/Mogre 1.7 you get a crash instead.

Solution:
Use the default resource group or create the wanted resource group manually.

So either go this way:

MaterialPtr moMaterial = MaterialManager.Singleton.Create("line_material",
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);


Or that way:

String resourceGroupName = "debugger"; // custom name
if (ResourceGroupManager.Singleton.ResourceGroupExists(resourceGroupName) == false)
ResourceGroupManager.Singleton.CreateResourceGroup(resourceGroupName);

MaterialPtr moMaterial = MaterialManager.Singleton.Create("line_material", resourceGroupName);



The wiki page MOGRE Line 3D I updated now.

By the way:
When you look to the ogre.log file you often see the reason of the crash.
In this case the log entry is:
14:05:31: OGRE EXCEPTION(5:ItemIdentityException): Cannot find a group named debugger in ResourceGroupManager::isResourceGroupInitialised at D:\Mogre BUILD\MogreBuilder__Result_bugFixed\Main\OgreSrc\ogre\OgreMain\src\OgreResourceGroupManager.cpp (line 1889)