Restaring Mogre - dispose() problems again
Hello, I need to restart MOGRE engine after changing some graphical settings (like resolution and so on), without killing the whole process and starting everything again. Unfortunately I get the following error after recreating the root object and trying to use LogManager singleton :
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Mogre.LogManager.LogMessage in d:\cubicalminds\mogreworld\mogre\mogre\src\auto\mogrelogmanager.cpp:line 97
at Wof.Controller.PerformanceTestFramework.Setup in f:\others\WoF\src\Controller\PerformanceTestFramework.cs:line 312
Here's the minimalistic code that produces the error:
root = new Root();
// In real code I'd like to do some stuff here, loading resources, rendering etc..
root = null;
root = new Root();
LogManager.Singleton.LogMessage("Testing2"); // exception!!!
public virtual void SetupResources(string cfgFilename)
// Load resource paths from config file
ConfigFile cf = new ConfigFile();
cf.Load(cfgFilename, "\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;
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);
just checked it, it seem that mogre, when dealing with singleton like the logmanager one, keep a pointer to the first native object created. so, when you dispose the root object, the native logmanager object is correctly destroyed, but not the managed singleton. i'm afraid that this problem is the same for every singleton object that the ogre root delete.
thanks for the report, i will see what could be done to fix it.
When you call to a Dispose() method, it marks for GarbageCollector to dispose them, and He will do it when he needs for. Even forcing GC to collect will not assure a sucessfull result.
Any ideas how to overcome this?
i have come up with a fix (just test it with your code and it work), all i need now is to build mogre and replace the current version. i will try to provide it today.
i have upload the new version, check the 1.6.4 thread : viewtopic.php?f=8&t=11241&p=64380#p64380
, please test it and let me know if it resolve all your recreations bugs.
Thank you GantZ, I'd love to use Mogre 1.6 however I need MHydrax for 1.6 to incorporate it in my project. I tried to do it myself, but I'm getting strange artifacts - viewtopic.php?f=8&t=9229&start=30#p58602
. I'm not sure whether this is an issue of Mogre 1.6 or MHydrax. Also it can be my lame knowledge of C++.
i will see what i could do to make this one work. i haven't used (or compiled) mhydrax/hydrax before, so i don't know how much time it will take me to get a working bug free version. i will post in the mhydrax thread as soon as i get something.
Please ask for help if you need it.
well, since i got some free time to work on mogre, i don't see why i shouldn't at least try to make some other plugins compiles with the last version
i usually don't care about plugins that have a maintainer, but since this one haven't anyone...
I'm gonna check new MHydrax as soon as I can. Thanks for the files!
Works for me without an issue ( part of my ChangeToWindowed, ChangeToFullscreen code ):
private void ShutDownEngine()
mRoot = null;
@nataz: The soluton you have given works with the snippet. However the same error pops up in the more complex example (when scene, camera and viewport are created and destroyed) when trying to log a message. I'll try updated Mogre 1.6 and report back.
MHydrax [...] but I'm getting strange artifacts [...]
I'm not sure whether this is an issue of Mogre 1.6 or MHydrax. Also it can be my lame knowledge of C++.
Some months ago I read in the Ogre related Hydrax thread. If I remember right, the artifacts are a general problem with updates. Look to the Hydrax forum
for the current state. Maybe it's not a problem of the wrapper.
If the problems are fixed in the original Hydrax - maybe they can help you, too. The people know the general problems and can give you ideas. Also post a screenshot there - then they see which kind of artifact it is.
By the way - can there be problems with Mogre? Because Mogre and MHydrax are both wrappers. So of the wrapped libraries are working correct - I suppose it should work correct with Mogre, too.