Sign in to follow this  

[.net] Efficient DirectX Lost Device Design ?

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

Beware - A beginners quistion. I've been trying for some time now to design a elegant way of handling Alt-Tab'ing and Ctrl-Alt-Delete's in both windowed and fullscreen Direct3D apps. The problem for me is to know what to do in the correct scenario for example: if a user Ctrl-Alt-Deletes in a windowed DirectX application I recive a lot of DeviceLostExceptions before a deviceNotresetException which then indicates I can Reset the device and continue. but if I'm in fullscreen and Alt-Tabs twice (out and in) I never get any DeviceNotResetException but a lot of DeviceLostExceptions but how do I know the difference And How do I know that I should respond to a DeviceLostException instead of waiting for a DeviceNotResetException. What I want is something like this -Device.Present failed (aka lost device) -Loop until either in windowed app I'm back into desktop after ctrlAltDelete in fullscreen app I've alt-tab'ed back into game. -end loop then I want to handle DirectXNoResetException DirectXLostDeviceException Is it something that I've not seen here, or some docs I've not properly studied? I've searched GameDev forums & Articles and googled for info too. but haven't been able to find a unifyed design for this problem. (btw Sorry for the bad english.)

Share this post


Link to post
Share on other sites
When a device becomes lost, you respond by pausing your game. You then wait until it enters the "resettable" status, aka "Device not-reset" (i.e. it can be reset). Then you release all resources from the default pool, reset, and recreate resources.

Share this post


Link to post
Share on other sites
How do I know its in "resettable" status? How do I know thats it gonna get in a resettable status (it don't get to resettable status if you Alt-tab out of fullscreen and in again).

should I try to recreate the device every once and awhile and then just reset it instead in case of notresetexception?

Share this post


Link to post
Share on other sites
What I've typically seen done is a try {} catch {} used in the game's main drawing loop. If the app fails when presenting or ending the scene because of "DeviceLostException", it goes into inactive mode. Every time your application goes to begin drawing it checks for this inactive state. It then calls Device.TestCooperativeLevel() to see if it can begin drawing again. If it receives a "DeviceLostException" it skips the drawing phase (the device is still lost -- out of focus). If the test receives a "DeviceNotReset" exception (meaning the device is back, but not reset), it calls device.Reset() and turns drawing back on again.

Dealing with invalidating and restoring objects is wonderful in .NET and very easy. Every time you created an object that needs to be invalidated and then restored you simply add an event to Device.DeviceLost and Device.DeviceReset. It will automatically calls all your invalidate and restore events at the appropriate times. I like to map Dispose() events too, for simplicity.

Share this post


Link to post
Share on other sites

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