Re: Line OnLostDevice() Exception



Thanks for the answer,

now i'm quite sure the problem is related to the Dispose() pattern i'm implementing... it seems that I was not disposing the Device so it was disposed by the finalizer, in a thread that was different from the one that actualy created it... now it seems that i fixed the problem, but I will have to implement a correct Dispose pattern anyway... Thank you so much for helping!

Giorgio Tino


ZMan ha scritto:
If you are adding your own event handlers you should make sure you turn of the automatic ones.. maybe something is getting confused there

I think its Device.AutoEventHandler = false; or somethink like that - the property is on the static Device class


"Giorgio Tino" <giorgio.tino@xxxxxxxxxxxx> wrote in message news:%23cszJ3RiHHA.3412@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

yes I do call the Dispose() myself... This is what I call:

Device d;
Line _line;

//
//...
//

d.DeviceReset += new EventHandler(this.OnDeviceReset);
d.DeviceLost += new EventHandler(this.OnDeviceLost);
d.DeviceDisposing += new EventHandler(this.OnDeviceDisposing);
d.DeviceResizing += new EventHandler(this.OnDeviceResizing);


//
//...
//

protected void OnDeviceLost(object sender, EventArgs e)
{
//
//...
//

if(this._line != null)
{
if(!this._line.Disposed)
{
this._line.Dispose();
this._line = null;
} }
//
//...
//
}

I've tried to comment out all the event handlers but the Reset one (I use those delegates to print out "Hello, now I'm disposing/resizing/losing etc..." :-) ) and it happens anyway... If I don't use any line at all, the same problem occurs for Fonts... The same exception but applyed to the Direct3D.Font objects I have... So it really seems like there is something wrong disposing the GDI stuff? The approach I use to Dispose those element is the same one I've explained above... Is there any known issue that can cause this behavior?

Even if I commnt out the Dispose() calls, it happens... To avoid this exception, the only thing I can do is not to use Fonts or Lines. Btw The application runs ok, so I think it is just some disposing problem...

Giorgio Tino

ZMan ha scritto:
Do you call Dispose yourself on the line object? If so then the Finalzer won't be called when you quit.



"Giorgio Tino" <giorgio.tino@xxxxxxxxxxxx> wrote in message news:eq4D53PiHHA.4596@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

I've got a problem using the Line class. Everything seems to work fine, but whenever I close my application, I always get this exception:

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Microsoft.DirectX.Direct3DX"
StackTrace:
at Microsoft.DirectX.Direct3D.Line.OnLostDevice()
at Microsoft.DirectX.Direct3D.Line.OnParentLost(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at Microsoft.DirectX.Direct3D.Device.raise_DeviceLost(Object i1, EventArgs i2)
at Microsoft.DirectX.Direct3D.Device.Finalize()

Any idea about it? Is the Finalize/Dispose called more than once? I've been trying to override all the Lost, Disposing methods, checking if the Line had already been Disposed and so on... My code seems to work fine, but sometimes after I've Disposed everything managing the Device Lost events, this exception occurs...

Thanks,
Giorgio Tino


.