Getting SEHException when running MOGRE application

Badspot

02-05-2015 18:29:27

So, I'm following the basic tutorial on how to embed an MOGRE into Windows.Forms (on OGRE page). I could compile the code without any problems and I checked if anything was right. But when running the application, It doesn't work and I receive a SEHException, locating here:

(MogreConfigFile.cpp)


My code in OgreForm.cs:
using Mogre;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Chuckya64_ULT
{
public partial class OgreForm : Form
{
Root mRoot;
RenderWindow mWindow;

public OgreForm()
{
InitializeComponent();

this.Size = new Size(800, 600);
Disposed += new EventHandler(OgreForm_Disposed);
Resize += new EventHandler(OgreForm_Resize);
}

void OgreForm_Resize(object sender, EventArgs e)
{
mWindow.WindowMovedOrResized();
}

void OgreForm_Disposed(object sender, EventArgs e)
{
mRoot.Dispose();
mRoot = null;
}

public void Go()
{
Show();
while (mRoot != null && mRoot.RenderOneFrame())
Application.DoEvents();
}

public void Init()
{
// Create root object
mRoot = new Root();

// Define Resources
ConfigFile cf = new ConfigFile();
cf.Load("resources.cfg", "\t:=", true);
ConfigFile.SectionIterator seci = cf.GetSectionIterator();
String secName, typeName, archName;

while (seci.MoveNext())
{
secName = seci.CurrentKey;
ConfigFile.SettingsMultiMap settings = seci.Current;
foreach (KeyValuePair<string, string> pair in settings)
{
typeName = pair.Key;
archName = pair.Value;
ResourceGroupManager.Singleton.AddResourceLocation(archName, typeName, secName);
}
}

// Setup RenderSystem
RenderSystem rs = mRoot.GetRenderSystemByName("Direct3D9 Rendering Subsystem");
// or use "OpenGL Rendering Subsystem"
mRoot.RenderSystem = rs;
rs.SetConfigOption("Full Screen", "No");
rs.SetConfigOption("Video Mode", "800 x 600 @ 32-bit colour");

// Create Render Window
mRoot.Initialise(false, "Main Ogre Window");
NameValuePairList misc = new NameValuePairList();
misc["externalWindowHandle"] = Handle.ToString();
mWindow = mRoot.CreateRenderWindow("Main RenderWindow", 800, 600, false, misc);

// Init resources
TextureManager.Singleton.DefaultNumMipmaps = 5;
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();

// Create a Simple Scene
SceneManager mgr = mRoot.CreateSceneManager(SceneType.ST_GENERIC);
Camera cam = mgr.CreateCamera("Camera");
cam.AutoAspectRatio = true;
mWindow.AddViewport(cam);

Entity ent = mgr.CreateEntity("ninja", "ninja.mesh");
mgr.RootSceneNode.CreateChildSceneNode().AttachObject(ent);

cam.Position = new Vector3(0, 200, -400);
cam.LookAt(ent.BoundingBox.Center);
}
}
}


My code in Program.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Mogre;

namespace Chuckya64_ULT
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
OgreForm form = new OgreForm();
form.Init();
form.Go();
}
}
}


I've tried re-installing everything, even compiled MOGRE by my own and it still doesn't work. Some help would be nice. Thanks in Advance,
Badspot.

Badspot

02-05-2015 19:04:43

(Reposted topic, because I'm not allowed to post any pictures in a post).

So, I'm following this tutorial here:
http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Mogre+Tutorial+-+Embedding+Mogre+in+Windows.Forms

I use newest MOGRE sdk, Visual Studio 2012. I followed the tutorial EXACTLY like they wrote it in there. I put in the reference to the DLL, etc. etc. All that worked. And it compiled fine and without problems. However, once I try to run the application, I get a SEHException.

This is my code in OgreForm.cs:
using Mogre;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Chuckya64_ULT
{
public partial class OgreForm : Form
{
Root mRoot;
RenderWindow mWindow;

public OgreForm()
{
InitializeComponent();

this.Size = new Size(800, 600);
Disposed += new EventHandler(OgreForm_Disposed);
Resize += new EventHandler(OgreForm_Resize);
}

void OgreForm_Disposed(object sender, EventArgs e)
{
mRoot.Dispose();
mRoot = null;
}

void OgreForm_Resize(object sender, EventArgs e)
{
mWindow.WindowMovedOrResized();
}

public void Go()
{
Show();
while (mRoot != null && mRoot.RenderOneFrame())
Application.DoEvents();
}

public void Init()
{
// Create root object
mRoot = new Root();

// Define Resources
ConfigFile cf = new ConfigFile();
cf.Load("resources.cfg", "\t:=", true);
ConfigFile.SectionIterator seci = cf.GetSectionIterator();
String secName, typeName, archName;

while (seci.MoveNext())
{
secName = seci.CurrentKey;
ConfigFile.SettingsMultiMap settings = seci.Current;
foreach (KeyValuePair<string, string> pair in settings)
{
typeName = pair.Key;
archName = pair.Value;
ResourceGroupManager.Singleton.AddResourceLocation(archName, typeName, secName);
}
}

// Setup RenderSystem
RenderSystem rs = mRoot.GetRenderSystemByName("Direct3D9 Rendering Subsystem");
// or use "OpenGL Rendering Subsystem"
mRoot.RenderSystem = rs;
rs.SetConfigOption("Full Screen", "No");
rs.SetConfigOption("Video Mode", "800 x 600 @ 32-bit colour");

// Create Render Window
mRoot.Initialise(false, "Main Ogre Window");
NameValuePairList misc = new NameValuePairList();
misc["externalWindowHandle"] = Handle.ToString();
mWindow = mRoot.CreateRenderWindow("Main RenderWindow", 800, 600, false, misc);

// Init resources
TextureManager.Singleton.DefaultNumMipmaps = 5;
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();

// Create a Simple Scene
SceneManager mgr = mRoot.CreateSceneManager(SceneType.ST_GENERIC);
Camera cam = mgr.CreateCamera("Camera");
cam.AutoAspectRatio = true;
mWindow.AddViewport(cam);

Entity ent = mgr.CreateEntity("ninja", "ninja.mesh");
mgr.RootSceneNode.CreateChildSceneNode().AttachObject(ent);

cam.Position = new Vector3(0, 200, -400);
cam.LookAt(ent.BoundingBox.Center);
}
}
}


And here is my code in Program.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Mogre;

namespace Chuckya64_ULT
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
OgreForm form = new OgreForm();
form.Init();
form.Go();
MessageBox.Show("Lol test");
}
}
}


Any idea what could be the cause of this? Or is the tutorial just too old or something? I even tried the same on Visual Studio 2010. The application doesn't run and also gives me a SEHException error. Some help would be nice.

Thanks in advance,
Badspot.

Beauty

03-05-2015 12:15:26

Hi Badspot,

welcome to our Mogre world.

I'm not shure what's your problem, but I have ideas.

When the Ogre library throws an exception, Mogre users see an SEHException.
To see the exception message, have a look to the ogre.log file.

Your screenshot looks like that you have a problem with a config file.
Maybe it's not found or a setting is not correct or a referenced plugin isn't found.

For example a typical newcomer problem is to define a needed plugin in the file Plugins.cfg and then the needed DLL file isn't inside of the binary directory.
To be shure to have all needed binary files, copy all binary files (of a binary bundle or the MogreBuilder output) to your binary directory.
Well, not all files are needed, but for error testing this is a good way.

Additionally you should download and start the DirectX updater ("DirectX End-User Runtime Web Installer").
http://www.microsoft.com/downloads/deta ... 6652cd92a3
Then you are shure to have all needed DirectX DLL files.

I hope this helps you to find out the problem.
If not, just post again.

compiled MOGRE by my own
By use of MogreBuilder or manually?

Beauty

03-05-2015 12:25:04

(Reposted topic, because I'm not allowed to post any pictures in a post).
I'm sorry about the trouble.

It's useful that you added a screenshot.
In the past the Ogre forums had much problems with spam. This is the reason why new users have restrictions.
I hope now it's fine.

Side note:
I merged both posts, because they are about the same topic.

Badspot

03-05-2015 14:32:10

(off-topic: Ah, I understand. Yes, I was in a hurry and so I didn't read the notes about how the posts are handled here. It's good to see how the forums handle the posts. It's similar to stackoverflow and motivates people to invest more time into their question topics and try out something on their own before asking.)

So, before I start posting my experience with the help you offered, some details:
OS: Windows 7 64-Bit
IDE: Visual Studio 2012 (C# Project for MOGRE)
Version: Mogre SDK 1.7.1

First, I did a dependencycheck which was offered in the sdk. I passed all tests and it let me successfully build the sample binaries. So, I definitely own all the runtimes and redistrutables I need. Now, I tried to create a new project, copied all binaries (mogre.dll + configs) into bin/debug and bin/release. I changed all relative paths to the media files, so they find them in C:\MogreSDK\media etc. etc. I checked if I did it to both output directories. Yes, I did. The code used in my projects is still the same by the way. Again, the code was able to successfully compile. No compiler errors. But once executing, I get this error:



The error says:
"Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information."

I was able to solve it myself by adding an App.config file into my project and writing this:

<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>


Compiled again and started again and now I get a SEHException again, but this time pointing to mRoot:



So, is it possible that the reason is maybe VS2012 itself or is the tutorial code too outdated already?

Badspot

03-05-2015 15:29:24

(Reposted topic, because I'm not allowed to post any pictures in a post).
I'm sorry about the trouble.

It's useful that you added a screenshot.
In the past the Ogre forums had much problems with spam. This is the reason why new users have restrictions.
I hope now it's fine.

Side note:
I merged both posts, because they are about the same topic.


Oh, I just posted about another error before (not accepted yet) but I got it fixed. It was some error in the plugin.cfg. I thought it would find the Plugin= dlls automatically, but it didn't. Then I saw that it had the extension "_d" (= debug) which it wasn't named in my output. I fixed it and now got it to work. I see a green ninja.

I'm now wondering if it's possible to make it a separate userControl, because I don't want to fill up the whole form.

Beauty

04-05-2015 00:06:21

Just quickly now:

built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime

The SDK binaries were build against .NET 2.0. So you can use it with applications, which compile against .NET 2.0, 3.0 or 3.5.

When you want to create a .NET 4 or later version, you need Mogre binaries, which are compiled against .NET 4.0.
For this use e.g. my precompiled binaries (here) or use MogreBuilder (Wiki and Repository).

Compiled again and started again and now I get a SEHException again
As I wrote before: Especially for this exception you should have a look to the ogre.log file.
Did you do? What's the exception message?

Oh, I just posted about another error before (not accepted yet) but I got it fixed. It was some error in the plugin.cfg. I thought it would find the Plugin= dlls automatically, but it didn't.
No, you have to tell Ogre, which plugins you want to use. For this you need the correct settings in the plugin.cfg file and the DLL files in your binary directory.

Then I saw that it had the extension "_d" (= debug) which it wasn't named in my output.
Normally you don't use the "_d" DLL files, even when your project settings are "Debug".
The DLL files with "_d" are build with "special settings" in the Ogre/Mogre build process. It means something like deep debug mode. By use of these DLL files (inclusive PDB files) you can look into the C++ layer below the Mogre wrapper. These binary files are only useful for finding Ogre bugs or high interest in learning Ogre internals.
Also you shouldn't mix Ogre DLL files, which are build in release and debug mode. Either use only debug build DLLs or only release build DLLs.

I'm now wondering if it's possible to make it a separate userControl, because I don't want to fill up the whole form.
You can add a Panel to your Form and clamp the renderwindow there. Then by resizing / moving the Panel you can adjust the output.

So, is it possible that the reason is maybe VS2012 itself or is the tutorial code too outdated already?
The tutorial was written many years ago but still should work. Maybe only some details changed. (e. g. the property "WorldPosition" is now called "_derivedPosition").
I hate the bad GUI style of VS2012. VS2013 looks similar, but has an improved GUI. If you can do it, I suggest to use VS2013 instead.
Nethertheless Mogre also works with VS 2010.

OK, no quick answer, although it's late.
I hope I could help.