Original Post
Hi Guys, Ive been having a bit of trouble with the above exception when using 2D fonts in Managed DirectX (C#.NET). It occurs when i close (i.e. click X, press esc, this.Close() etc) my window and after reading through some resources and posts on here i think its related to my pants resource disposing :) Ive had a go at trying to solve this but i dont think i totally grasp the concepts enough to know where to place my method calls properly. I've outlined my code below and explained how its called etc. If someone could very kindly point me in the right direction of where im going wrong it would be absolutely grand :D My app entry is a AppEntry class which has a static void Main() which calls: renegadeWindow is my render target window and is just a win form. The game loop is controlled via the PeekMessage method from Tom Miller's blog using the ApplicationIdle etc and that basically calls a method in a seperate class "InitEngine". This basically just has a list of commands to say, render the FPS on screen, render some sprites, start stop drawing etc such as here: All it does it has a Form object passed into the InitEngine constructor which grabs the device etc. My particular scene to render is indexBuff (a quick test im playing with to try out index buffers), so it just draws that and my fps counter inbetween some BeginRender() and EndRender() methods. Now i have implemented in my IndexBuff class an overriden Dispose() method similar to one Peter Germishuys used in a similar thread on here. My question is how do i call it? Would i place it before the core.BeginRender() in a disposing check? Ive tried playing around with it but i either get an error upon the form loading (object ref not set, as presumably im destroying the object before i can use it) or i get the NullRefError when i exit the form. Any help or direction that can be given would be greatly appreciated. It's been driving me insane! [bawling] If you need more clarification on how my (admittedly simple, yet pants) engine works, please let me know. I never was any good at explaining things :(
RenegadeWindow renegadeWindow = new RenegadeWindow();
Application.Idle += new EventHandler(renegadeWindow.OnApplicationIdle);
Application.Run(renegadeWindow);
public InitEngine(Form form)
{
core = new Core(form);
device = core.Device;
indexBuff = new IndexBuff(core);
frameRate = new FrameRate(core);
}
public void Render()
{
try
{
core.BeginRender();
frameRate.RenderText();
indexBuff.Render();
core.EndRender();
}
catch (Exception ex)
{
MessageBox.Show("An error has occured: " + ex.Message + "\n\n" + ex.StackTrace);
}