16-04-2008 14:31:40

Hi All,

I'm trying to make an application using MOGRE. I wanted MOGRE to be initialized with a windows form that I created. Here's how I initialized MOGRE...
private void initOgre()
// Create the OGRE root object
m_ogre_root = new Mogre.Root("Plugins.cfg");

// Define resources
ResourceGroupManager.Singleton.AddResourceLocation(".", "FileSystem", "General");

// Initialise all resource groups

// Setup the render system
RenderSystemList render_systems = m_ogre_root.GetAvailableRenderers();
IEnumerator<RenderSystem> render_system_itr = render_systems.GetEnumerator();
RenderSystem render_system = null;
bool found_render_system = false;
string render_system_name;
while (render_system_itr.MoveNext())
render_system = render_system_itr.Current;
render_system_name = render_system.Name;
if (render_system_name.CompareTo("OpenGL Rendering Subsystem") == 0)
found_render_system = true;
if (found_render_system)
render_system.SetConfigOption("Full Screen", "No");
render_system.SetConfigOption("Video Mode", "800 x 600 @ 32-bit colour");
m_ogre_root.RenderSystem = render_system;
throw new Exception("Could not find the required rendering system.");

// Create the render window
m_ogre_root.Initialise(false, "VRML2Mesh Render window");
NameValuePairList misc = new NameValuePairList();
misc["externalWindowHandle"] = Handle.ToString();
uint window_width = (uint)Width;
uint window_height = (uint)Height;
m_render_window = m_ogre_root.CreateRenderWindow("VRML2Mesh", window_width, window_height, false, misc.ReadOnlyInstance);

// Create the scene manager
m_scene_manager = m_ogre_root.CreateSceneManager(SceneType.ST_GENERIC);
Camera cam = m_scene_manager.CreateCamera("Camera");
cam.AutoAspectRatio = true;

The disposing of the OGRE root is done in the Dispose event of the form...
private void MainForm_Disposed(object sender, EventArgs e)
m_ogre_root = null;

The initialization of the OGRE works fine... but then once I exit the application I get this error...
An unhandled exception of type 'System.AccessViolationException' occurred in System.Windows.Forms.dll

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

What I believe is happening is that when the root is being disposed it tries to delete or destroy the Windows Form... which creates this problem. It's just a wild guess.. Is there a work around for this? Thanks in advance.


16-04-2008 14:57:35

Just a guess but i've something like this running:

while (app.gfxRunning)
app.gfxRunning = app.gfxRunning && !window.IsDisposed;

root = null;

So i dispose the root-object after the window is gone, and it seems to work. So maybe Form.Dispose is just the wrong place?


16-04-2008 15:03:22

In my case, i do not have a continuous while loop running... i intend to use OGRE to make some conversions of file formats to OGRE mesh format. This file type is a custom VRML based file type. So i can't use the usual VRML2Mesh to do the job. So I have to create one of my own. AFAIK based on my experience in OGRE (C++) I need to create a render window based on a render system for the mesh manager and other managers to be initialized. I only need to use these managers and nothing else. So, in short, I don't know which other place I can Dispose the root object.


09-05-2008 21:22:33

I have the same problem, the exceptions are of two types - pure virtual call
or memory error. Laws which were unable to identify what. Both are initiated by Root.Dispose.
the only way to avoid it to make a handler like this

except System.Runtime.InteropServices.SEHException:
except Exception:

I use WeifenLuo.WinFormsUI.Docking.


10-05-2008 17:26:18

forgot to say strange - under debugger everything works perfectly