Jump to content
  • Advertisement
Sign in to follow this  
Code_X

need help with loss devices

This topic is 5057 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I know my problem is not very well described, but here goes anyway... When I alt-tab out of my game and then go in again, I lose my Device for some reason (I know, thats normal. i'd like to know why though). Now when I try to draw again after restoring it, it just wont work. When i try to draw a simple sprite, i get a System.NullReferenceException at Microsoft.DirectX.Direct3D.D3DX.GetUnmanagedTexture(Texture tex) at Microsoft.DirectX.Direct3D.Sprite.Draw(Texture srcTexture, Rectangle srcRectangle, Vector3 center, Vector3 position, Int32 color) at Microsoft.DirectX.Direct3D.Sprite.Draw(Texture srcTexture, Rectangle srcRectangle, Vector3 center, Vector3 position, Color color) I tried to reload all my Textures (since i suppose they got "lost" as well) but it won't change anything. If it is a common problem please tell me what i should do. And an explanation of what happens when the Device is lost would be nice too :D feel free to just give me links to other posts or ressources. I searched a bit ut couldnt find anything

Share this post


Link to post
Share on other sites
Advertisement
When a device is lost, anything to do with your game that resides on the graphics card is destroyed because another application is in focus and is using it instead.

You need a device validation function that you call each frame before rendering. You need to test the device using it's member function TestCooperativeLevel(). If it returns D3DERR_DEVICELOST then the device is still lost and you just iterate on to the next frame and try again.

If the function returns D3DERR_DEVICENOTRESET then you need to release certain elements of your program before resetting the device. Essentially, this is anything that has been created with the D3DPOOL_DEFAULT flag rather than D3DPOOL_MANAGED (e.g dynamic vertex buffers, index buffers, render textures, ID3DXMesh* etc). If you use ID3DXFont* then you have to release them using the font's member functions OnLostDevice() because ID3DXFont* uses default pool entities.

You then reset the device. If that returns successful you need to recreate everything you released above. This isn't as bad as it seems because most things you create will be D3DPOOL_MANAGED anyway and you can just ignore them because they restore themselves. ID3DXFont's have a member function OnResetDevice() which you can call to restore them.

You also need to reset default render states (Z buffering, lighting etc) and reset your matrices (mainly projection because your view and world are most likley calculated each frame anyway).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!