Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - Recovery From A Device Lost State ( or when your media no longer exist )

Author
Message
Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 9th Jun 2012 14:32
One of the more important aspects that DBPro should have designed itself around was designing it to easily handle a Device Lost State. Unfortunately it doesn't. This thread below is my take on it with a DeviceLost DLL to use the DBPro internals to have commands to help the user know when a device is lost and when it's reset. The only problem I have with it currently is alt-tabbing quickly which will cause a crash.
http://forum.thegamecreators.com/?m=forum_view&t=197641&b=18&p=0

Below is how I would do it without using this DeviceLost DLL. Just pure DBPro code.

Alt-tabbing, pressing the windows key, or even the ctrl-alt-del key combo will cause a DirectX 9 exclusive fullscreen mode device to be lost and will need to be reset. This can also happen in a windowed mode program with ctrl-alt-del key combo. There could be other ways.

When the device lost/reset happens, media resources will be lost. So for example, if you ever had alt-tab'd out of an exclusive fullscreen mode and had your program then crash on you because it no longer can find an image to be used for the paste image command, that is probably the cause of it. A device lost/reset had happened.

The link above shows how I would use the actual device lost/reset states that DBPro itself signals. But upon discovery, we can find out if a device lost/reset happened with out all that info from the dll. We can simply check to see if an image exists or not.

We can load an image specifically for this while not needing to use it for anything else. If this image no longer exists sometime during your program and you know your code didn't delete it, it very well may mean that a device lost/reset had occurred. So we simply take this opportunity to reload all the media that we currently need. [Note: This code doesn't show it, but for your own exercise and as you probably already know, you should always delete what you don't use and make sure you media exists first so you don't reload them when you don't need to]

Here's the code:



ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 11th Jun 2012 11:22
just tagging in here too tired to read so much right now...

Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 28th Jun 2012 08:01
I took the SetupWindow_LoadMedia() function out from the above code and made it so it wouldn't call "set window" again. This helps cut down the screen flickering.

Also this example doesn't need an image file to be loaded. It creates it's own image. I did that to make it easier for you to test this code out without having to find your own image and making sure it calls it. I should of done that the first time.

* So far this hasn't failed on me yet. I need to test this out on a bigger program. Please share your experience with us if you try this method. Thanks.




ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY

Login to post a reply

Server time is: 2024-03-28 15:35:50
Your offset time is: 2024-03-28 15:35:50