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.

DLL Talk / Device Lost DLL - Check when your progam needs to re-create resources

Author
Message
Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 9th Jun 2012 05:32 Edited at: 9th Jun 2012 13:21
Here's a dll that has commands to help let you know when your program loses it's resources (ie: alt-tab, ctrl-alt-del, etc... ) in a fullscreen or windowed state. Not perfect, but better then nothing. [ <--- EDIT: Force Reloading is better! Scroll down the thread to see my example of Force Reloading ]

Checking for a lost device in the exclusive fullscreen state can be a little bit fiddly. For example, sometimes when my app is in a fullscreen state, on windows Vista, I can hit ctrl-alt-tab and then select the "Start Task Manager" real quick. Then for some reason, my DBPro app will not detect that it no longer has focus and continue through the code and then crash as if it didn't allow it to have time to reset the lost device. For the fullscreen part in my example code, I use "Screen Invalid" to detect when the DBPro program has focus or not. "Screen Invalid" needs to halt the DBPro program and wait until it has focus again, restore the window and then reload graphics, etc... before using those resources again.

* another weird situation with fullscreen mode, is that I have to check for a "device lost" again before I reload my resources. Otherwise, it won't work for me right.

Mabie somebody can make this example bullet proof. Or mabie this may help to get the DBPro's Source Code fix'd in the future to have a solid Device Lost functionality.

Seems to work great in regular window mode. This functionality comes directly from DBPro. This dll returns a 1 on the commands when the DBPro callback routines are called and used by DBPro's internals. Otherwise, they return 0. DLL source code below under DBPro Example code.

I have attached a .rar archive on this post.
It includes:

- plugins-user folder:
DeviceLost.dll

- Keywords folder:
DeviceLost.ini

- DeviceLost.DBPRO
- DeviceLost.DBA
- grass.bmp ( from DBPro's included Media )
- Application.exe ( compiled DeviceLost Program )

DBPro Device Lost Example Code:
[ Set WindowModeOn to 0 for windowed mode or 1 for fullscreen mode ]



C++ Code for the DeviceLost.dll
[DeviceLost.h]


[DeviceLost.cpp]




Edit: lol , I just realized the grass.bmp is actaully a picture of dirt or rock. Don't know where I got it from.

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

Attachments

Login to view attachments
GIDustin
15
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 9th Jun 2012 06:48
I tested it myself and it works great in windowed mode. I added some code to count on the screen how many times it reloaded the media.

I can finally make a project and not have to include a huge disclaimer at the end listing all the possible ways of crashing it!

Thank you sir!
Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 9th Jun 2012 07:24 Edited at: 9th Jun 2012 07:31
Quote: "I can finally make a project and not have to include a huge disclaimer at the end listing all the possible ways of crashing it!"


lol

np problem GIDustin. I'll try to think up of other ways to make this more solid.


Clarifying on what I said above, when a program drops out of an exclusive fullscreen mode, the program has to wait until it gets back into fullscreen mode before it can continue on after a reset. The example given above can sometime screw up and try to continue on in fullscreen mode and crash. I might have to create some kind of Win32 command to help a fullscreen device lost to work/reset correctly all the time.

* If anybody has any ideas, please let you voice be heard. Thanks

ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
GIDustin
15
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 9th Jun 2012 08:09
could you use IanM's "has focus()" command?
Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 9th Jun 2012 08:25 Edited at: 9th Jun 2012 08:51
Quote: "could you use IanM's "has focus()" command? "


I'll try that.

EDIT: I'll try writting a call dll for that. Matrix 13 needs a msvcr71.dll.

EDIT:
Adding "SLEEP 2000" after the fullscreen after the device reset is perfect for when ctrl-alt-del out of fullscreen. It allows it time for DBPro to register that it is no longer in focus.

But, when alt-tabbing out of fullscreen and trying to get back into fullscreen mode as quick as you can... doing that continuously, well mess it up too. So, trying to think up a quick solution for that.

ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
zeroSlave
14
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 9th Jun 2012 09:07
Thanks for the hard work, Todd! This seems like a pretty great solution for losing the media after losing the focus.

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 9th Jun 2012 11:03 Edited at: 9th Jun 2012 11:27
Thanks zeroSlave


But not so fast...

Now that I added some 3D elements, in windowed mode, after the device gets reset from a `ctrl-alt-del` scenario... the text and image disappears, but the blue background and sphere stays.

But it works alright with fullscreen ( except if you try to 'alt-tab exit' fullscreen and enter back into it real quick... it will likely fail )

Here's what I have so far:




** also note that I didn't spell the global variable correctly in the first snippet.
it should be:
GLOBAL App_WindowModeOn as INTEGER



EDIT: [Instead of Double posting]
Ok, it was that I wasn't checking for Device Lost for a 2nd time like I did with the fullscreen mode which gave me weird results. Calling DeviceLost for 2nd time is weird in itself. Here's the updated code that works for windowed. Still have the fullscreen quick alt-tab out and in problem.



ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 9th Jun 2012 13:04 Edited at: 9th Jun 2012 14:37
[sry double post ]



FORCE RELOAD is better!



Even though the DeviceLost dll can be used, the quick alt-tab out and in from fullscreen will crash most likely. I can't figure it out. I even used the Win32 functions "Get Focus" and "GetModuleHandle" to compare when the program's window is no longer focus and it still will not set device lost in time before it try's to call the paste image command resulting in the crash.

I just don't know.


But what I do know is...

We know that when a Device Reset happens our resources get lost. So with that simple theory, we can just use one image for use to detect for when a device is lost. Simply check if the image exists or not at the top of your loop. Just keep the image number separate from everything else and never use it for anything else.

Yup that simple.

Here's the source code that works for both fullscreen and windowed mode without fail: [Well at least it worked solid for me ]

EDIT: And no DLL needed ! grass.bmp is included in the first post's download. Or you can just use your own image.





* Let me know what ya thinks about this code. Thanks
** I threw this code in the code snippets forum so it won't get to easily lost down the road.

ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY
GIDustin
15
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 9th Jun 2012 18:30
We've tried the "temp image" route before, but it still failed in certain scenarios. However, I could not get your latest code snippet to fail...

I am going to add the check function to the top of my loop and try it out.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 11th Jun 2012 11:18
tagging in

Login to post a reply

Server time is: 2024-04-16 23:56:52
Your offset time is: 2024-04-16 23:56:52