Destroying a renderwindow and cleaning up

Luth

25-04-2010 10:27:52

Hi.

I'm playing around a little with Mogre and have some problems with it. (Apart from taking a long time to get it running in VS2010 :mrgreen: )
Everytime i close my application, i get an ObjectDisposedException. The application is started in the following way,
using a Singleton instance containing a Windows Form.

Application.Run(Core.getSingleton().Config.Graphics.Window);

I am creating my renderwindow like this:

Window = new Form();
...
MRoot.Initialise(false, "MainWindow");
...
NameValuePairList misc = new NameValuePairList();
misc["externalWindowHandle"] = Window.Handle.ToString();
MRenderWindow = MRoot.CreateRenderWindow("MainWindow",(uint)Screenwidth,(uint)Screenheight,Fullscreen,misc);


So i do not let Mogre create the window itself, but initialize it on an existing form.
Next i registered a formclosing-event and a framehandler to do a clean up, after i finished rendering.


Config.Graphics.MRoot.FrameStarted += new FrameListener.FrameStartedHandler(Handle_FrameStarted);
Config.Graphics.Window.FormClosing += new FormClosingEventHandler(Window_FormClosing);
Config.Graphics.MRoot.StartRendering();
Shutdown();
...
void Window_FormClosing(object sender, FormClosingEventArgs e)
{
StopRendering = true;
}
...
bool Handle_FrameStarted(FrameEvent evt)
{
return (!StopRendering);
}


The Problem is: It seems that Mogre is destroying the renderwindow by itself, when closing down. It doesn't care about, if it has created the
renderwindow or just been given a window handle. So everytime i close my form, i get an ObjectDisposedException for the form used in
" Application.Run(Core.getSingleton().Config.Graphics.Window)". Is that the intented behaviour? And if so, does anyone have an idea how
i can work around it, except simply suppressing the exception?

The second thing i want to ask is, whether there is a general rule of thumb, what resources i have to clean up myself and what is done by Mogre.

Do i have to dispose the singleton managers (like ResourceGroupManager or MaterialManager) and / or materials myself?
Do i have to dispose or set null all the MaterialPointers, Meshpointers, SceneNodes, Entities or other resources?
Probably yes, since all those things are created by an unmanaged dll, but i would feel better if someone could clear that up for me.

Thanks for answering. :D

Luth

25-04-2010 17:28:28

Argh! Answer to myself:

You are an idiot. There is no need to call Application.Run(ARenderWindow); ...


Application..::.Run Method
Begins running a standard application message loop on the current thread.


Since Mogre starts it's own Loop with MRoot.StartRendering(); one can skip that application.run(). Just create the Form, give the handle to Mogre and start rendering.
Then it is no problem if Mogre destroys the form when existing, since no one needs it anymore.

Now it's only left to find out, what i may need to clean up manually and what is disposed by Mogre itself.

imi

01-05-2010 11:39:26

(Apart from taking a long time to get it running in VS2010 :mrgreen: )

How did you got it run under VS2010? (under .NET 4.0?) I tried to compile from scratch but always got severe problems with the tool chain (e.g. AutoWrapper) or with outdated patch files and wrong directories etc..

Can you commit your solution and project files and the patch you had to make to Ogre and Mogre (including which version the patch is based on) somewhere? Would be most appreciated. :)

Ciao, Imi.

Luth

01-05-2010 19:00:56

Sorry imi, can't help you there. With "get it running" i only meant to be able, to use debug mode in VS2010, which
gave me some trouble before. Also i'm running it with .Net 3.5 currently. After failing several times, to compile it from
the mercury sources and spending lots of hours, i simply gave up on that and use it as it is. :roll: