juharkonen
03-11-2008 14:45:26
I'm not sure if this is Ogre or Mogre issue but I decided to post to the Mogre forums as I'm using Mogre and have not tried to reconstruct the errors with Ogre.
My application is trying to start Mogre, close it and then start it again. However I get an AccessViolationException if I don't dispose the ResourceGroupManager singleton manually, and a NullReferenceException from TextureManager when I try to set the default number of mipmaps.
I understood that disposing the ogre root object was enough as most of the samples only dispose the root. I suspect that the problem may be caused by singletons and/or static members not being initialized properly after reinitialization. Here's a little program for reconstructing the problem (you have to add references and setup ogre resources accordingly to run it). I have tested this with both OpenGL and Direct3D renderers and they behave identically.
Any idea if it is possible to do reinitialization with Mogre?
My application is trying to start Mogre, close it and then start it again. However I get an AccessViolationException if I don't dispose the ResourceGroupManager singleton manually, and a NullReferenceException from TextureManager when I try to set the default number of mipmaps.
I understood that disposing the ogre root object was enough as most of the samples only dispose the root. I suspect that the problem may be caused by singletons and/or static members not being initialized properly after reinitialization. Here's a little program for reconstructing the problem (you have to add references and setup ogre resources accordingly to run it). I have tested this with both OpenGL and Direct3D renderers and they behave identically.
class Program
{
static void Main(string[] args)
{
// Initialize ogre
Root root = new Root();
Config(root);
InitializeResources();
root.Initialise(true);
TextureManager.Singleton.DefaultNumMipmaps = 5;
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();
// ResourceGroupManager has to be disposed manually in order to avoid
// AccessViolationException later on when calling ResourceGroupManager.Singleton.AddResourceLocation
ResourceGroupManager.Singleton.Dispose();
// Dispose the root
root.Shutdown();
root.Dispose();
// Create new root and initialize again
root = new Root();
Config(root);
// Call to ResourceGroupManager.Singleton.AddResourceLocation will cause
// an AccessViolationException if ResourceGroupManager was not disposed
InitializeResources();
root.Initialise(true);
// Attempt to set the number of mipmaps causes NullReferenceException from inside Mogre.TextureManager.get_DefaultNumMipmaps.
if (TextureManager.Singleton != null)
{
TextureManager.Singleton.DefaultNumMipmaps = 5;
}
root.Dispose();
}
private static void Config(Root root)
{
// Try to load settings from config file
//if (root.RestoreConfig() == false)
{
// Failed to load - show dialog
if (root.ShowConfigDialog() == false)
{
// User cancelled
//return false;
}
}
}
private static void InitializeResources()
{
// Load resource paths from config file
ConfigFile cf = new ConfigFile();
cf.Load("resources.cfg", "\t:=", true);
// Go through all sections & settings in the file
ConfigFile.SectionIterator seci = cf.GetSectionIterator();
String secName, typeName, archName;
// Normally we would use the foreach syntax, which enumerates the values, but in this case we need CurrentKey too;
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);
}
}
}
}
Any idea if it is possible to do reinitialization with Mogre?