Sign in to follow this  

need help with loss devices

This topic is 4836 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
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

This topic is 4836 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this