Skip to main content
gamedev.net
🔒 Locked

Problem in Sprite.OnLostDevice()

Started by radiationz 5 replies 1.4k views
Original Post
radiationz
radiationz
i am using c# with direct3d. I am using an instance from Sprite and when i close my program i think something wrong with deconstructing sprite... it gives me this: System.NullReferenceException was unhandled Message="Object reference not set to an instance of an object." Source="Microsoft.DirectX.Direct3DX" StackTrace: at Microsoft.DirectX.Direct3D.Sprite.OnLostDevice() at Microsoft.DirectX.Direct3D.Sprite.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 help will be appreciated, thnx.
Evil Steve
Evil Steve
I'm not a C# guy, but it looks like you've destroyed the sprite at some point before you try to call OnLostDevice() for it, meaning you get a null pointer (null reference) exception.
radiationz
radiationz
Thnx for response but I didnt destroy sprite... i created it at the beginning only, this exception happens when i close the program. Any help will be appreciated, thnx..
remigius
remigius
Try to expicitly dispose the device before you close the application, by calling yourDevice.Dispose() in the Form's closing event, maybe that'll help.

If I understand the problem correctly, the Sprite is trying to react to the DeviceLost event fired when the form is closed and something is going wrong there. My guess is that something else is already set to null internally when the form is closed, causing this error.
radiationz
radiationz
I did what you said but same error occurs.. :( I hope this problem get fixed ASAP and thank u all for ur help..
Armadon
Armadon
I agree with Remigius,
Make sure you take a look at the Disposal pattern. You are releasing the device and then the sprite is still trying to render. You will have to dispose of the sprite and make sure it's disposed and then take care of the device.

I hope this helps.
Take care.
radiationz
radiationz
Thnx armadon it works :) , The problem was that the spirte should be disposed manually before device.. thnx

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.