Bug Report: Mogre leaves corrupted memory when it destructs

PikminDoctor

29-03-2008 13:38:18

This works in C++:

#include "Test.h"

void RunOgre()
{
try
{
// Create application object
TestApp app1;
app1.go();
}
catch( Ogre::Exception& e )
{
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
}
}


#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
{
RunOgre();
RunOgre();
return 0;
}
(...continued next post because i've reached character limit)

PikminDoctor

29-03-2008 13:39:42

But when we try to do the same thing in Mogre, it thinks the singleton still exists, even though we've left the function!!!



using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Mogre;
using System.Drawing;

namespace Tutorial05
{
static class Program
{
static void RunOgre()
{
try
{
TestApp app1 = new TestApp();
app1.Go();
}
catch (System.Runtime.InteropServices.SEHException)
{
if (OgreException.IsThrown)
MessageBox.Show(OgreException.LastException.FullDescription,
"An exception has occurred!");
else
throw;
}
}

[STAThread]
static void Main()
{
RunOgre();
RunOgre();
}
}
}


Try it out!

raygeee

01-04-2008 22:22:37

Mogre is Managed Code with Garbage Collection, Ogre is Unmanaged. The Singleton (static variable) doesn't get cleaned up because it's still referenced. Normally you would call something like Dispose() or Destroy() to nullify those variables.

Update: With Disposing my RenderWindow, ResourceGroupManager.Singleton, TextureManager.Singleton and OgreRoot I get the Tutorial5 running the second time until ResourceGroupManager.Singleton.InitializeResourceGroups() calls TextureManager.Singleton.DefaulNumMipMaps internally and causes a System.AccessViolationException to be thrown.
Same problem like you had in the other thread already (http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=6466).