vitefalcon
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...
The disposing of the OGRE root is done in the Dispose event of the form...
The initialization of the OGRE works fine... but then once I exit the application I get this error...
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.
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
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();
// 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;
break;
}
}
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;
}else{
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;
m_render_window.AddViewport(cam);
}
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.Dispose();
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.