Seleste
04-11-2010 18:46:09
I've been using Mogre for throwing together a quick and easy visualisation for a physics simulations class. I've been using the Direct3D rendersystem on my development station with no issue, however the person grading wants the program to work on lab computers that don't have Direct3D setup. Thankfully, switching to OpenGL works fine, so I went about to implementing a way of having it fall back to OpenGL if Direct3D fails. At first I just checked for null return values on Root.GetRenderSystemByName() like so:
However, it turns out plugin load failure is thrown on Root construction. So the unhandled constructor exception gives me a null _root and nothing works. So I added an exception handler when constructing the root:
The fallback plugins cfg simply doesn't have Direct3D9 render system enabled, and everything seems to initialise fine. The root gets assigned the OpenGL rendersystem at the null check from before.
However, it turns out the first attempt to create the root does allocate a native root to an extent, as I can look with the debugger during the exception to see Mogre.Root.Singleton._native set. Somehow, this incomplete Root gets garbage collected afterwards, causing Mogre to crash on the root's Finalizer, and I haven't found any way to avoid this. Is this a bug with regards to incomplete Root construction, or am I handling my RenderSystem fallback wrong?
RenderSystem rs = _root.GetRenderSystemByName("Direct3D9 Rendering Subsystem");
if (rs == null)
rs = _root.GetRenderSystemByName("OpenGL Rendering Subsystem");
However, it turns out plugin load failure is thrown on Root construction. So the unhandled constructor exception gives me a null _root and nothing works. So I added an exception handler when constructing the root:
// Create root object
try
{
_root = new Root();
}
catch (System.Runtime.InteropServices.SEHException ex)
{
if (!Mogre.OgreException.IsThrown || Mogre.OgreException.LastException.Number != OgreException.ExceptionCodes.ERR_INTERNAL_ERROR)
{
throw ex;
}
else
{
if (_root == null)
_root = new Root("plugins_fallback.cfg");
}
}
The fallback plugins cfg simply doesn't have Direct3D9 render system enabled, and everything seems to initialise fine. The root gets assigned the OpenGL rendersystem at the null check from before.
However, it turns out the first attempt to create the root does allocate a native root to an extent, as I can look with the debugger during the exception to see Mogre.Root.Singleton._native set. Somehow, this incomplete Root gets garbage collected afterwards, causing Mogre to crash on the root's Finalizer, and I haven't found any way to avoid this. Is this a bug with regards to incomplete Root construction, or am I handling my RenderSystem fallback wrong?