Google

Problem with creating a material

Discussion regarding the Managed .Net Wrapper for Ogre, MOGRE (http://sourceforge.net/projects/mogre)

Moderators: OGRE Team, MOGRE Moderators

Problem with creating a material

Postby maaschn » Sun Feb 05, 2012 7:44 pm

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:
Code: Select all
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
maaschn
Gnoblar
 
Posts: 4
Kudos: 0
Joined: 05 Feb 2012

Re: Problem with creating a material

Postby smiley80 » Mon Feb 06, 2012 9:16 am

Check 'Ogre.log' for errors.
I guess you don't create the 'debugger' resource group:
Code: Select all
ResourceGroupManager.Singleton.CreateResourceGroup("debugger");
There was a SIGNATURE here. It's gone now.
smiley80
Gnoll
 
Posts: 670
Kudos: 47
Joined: 13 Nov 2008
Location: Germany

Re: Problem with creating a material

Postby maaschn » Mon Feb 06, 2012 9:44 am

Thanks so much. That was the correct guess.
maaschn
Gnoblar
 
Posts: 4
Kudos: 0
Joined: 05 Feb 2012

Re: Problem with creating a material

Postby zarfius » Mon Feb 06, 2012 11:55 am

maaschn wrote: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:

Code: Select all
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);
}   
Craftwork Games - hand crafted entertainment.
http://www.craftworkgames.com/
User avatar
zarfius
Goblin
 
Posts: 234
Kudos: 24
Joined: 09 Jul 2008
Location: Brisbane, Australia

Re: Problem with creating a material

Postby Pyritie » Wed Feb 08, 2012 6:52 pm

zarfius wrote:
maaschn wrote: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:

Code: Select all
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.
I use Mogre, BulletSharp, LuaNetInterface, irrKlang, and Miyagi! | Ponykart
Image
User avatar
Pyritie
Greenskin
 
Posts: 133
Kudos: 6
Joined: 06 Mar 2009

Re: Problem with creating a material

Postby Beauty » Wed Apr 11, 2012 1:03 pm

maaschn wrote:MaterialPtr moMaterial = MaterialManager.Singleton.Create("line_material", "debugger");

You use my code for 3D lines, which I published in the wiki. :D

maaschn wrote: 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:
Code: Select all
MaterialPtr moMaterial = MaterialManager.Singleton.Create("line_material",
    ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);


Or that way:
Code: Select all
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)
Help to add information to the wiki. Also tiny edits will let it grow ... :idea:
Add your country to your profile ... it's interesting to know from where of the world you are.
IRC chat ... Mogre: irc://freenode/#mogre ... Ogre: irc://freenode/#ogre3d
User avatar
Beauty
OGRE Community Helper
 
Posts: 1596
Kudos: 35
Joined: 09 May 2007
Location: Germany


Return to MOGRE

Who is online

Users browsing this forum: No registered users and 2 guests