wyrd Posted October 17, 2003 Posted October 17, 2003 I have a method here which tests the cooperative level of the device and attempts to restore the surfaces if it has to; /// <summary> /// Insures that the surfaces for this GameSurface are accessible. /// </summary> private void _checkSurfaces() { if (_device.TestCooperativeLevel() == false) { // TODO: Bug - Throws error in FullscreenExclusive. _device.RestoreAllSurfaces(); } } The problem is, it throws an exception when trying to perform RestoreAllSurfaces(). An unhandled exception of type 'Microsoft.DirectX.DirectDraw.WrongModeException' occurred in microsoft.directx.directdraw.dll Additional information: Error in the application. I've also tried catching the SurfaceLostException, but it gives me the same error when trying to perform RestoreAllSurfaces(). I get no errors when running in windowed mode, so I can only assume it has something to do with FullscreenExclusive. Any ideas on how to fix this? Quote Gamer extraordinaire. Programmer wannabe.
*Experts* Nerseus Posted October 18, 2003 *Experts* Posted October 18, 2003 Before you restore you have to manually clean up any resources defined in a pool NOT part of managed (can't remember the enum to look for offhand). That may or may not be your problem. Have you run dbmon, a tool in the SDKs bin folder, to see what it shows as an error? It often gives more detailed info about DX errors. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
wyrd Posted October 18, 2003 Author Posted October 18, 2003 Hmm.. in a pool? Do you mean I have to Dispose and reinstantiate every single surface in my game? (basically as if I was first loading up the game). I've never used dbmon, I'll take a look and see if I can figure out how it works. :) Quote Gamer extraordinaire. Programmer wannabe.
wyrd Posted October 18, 2003 Author Posted October 18, 2003 I've looked at a few tutorials to try and figure out the problem (DD documentation sucks). The only way I've found is to dispose of all of my surfaces and reinstantiate them. This is really, really ugly because it could cause a performance hit. How do you handle this in your Ms. Pacman game? Quote Gamer extraordinaire. Programmer wannabe.
AndreRyan Posted October 18, 2003 Posted October 18, 2003 This may seem obvious and is probably of no use but 'Microsoft.DirectX.DirectDraw.WrongModeException' is usually thrown when you try to use a DirectDraw Device when you've lost exclusive mode, you're supposed to loop until it's restored: private void _checkSurfaces() { if (_device.TestCooperativeLevel() == false) { do{ Application.DoEvents(); } while(_device.TestCooperativeLevel() == false); _device.RestoreAllSurfaces(); //Reload all pictures from file } } Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
wyrd Posted October 18, 2003 Author Posted October 18, 2003 (edited) I noticed that you have this line; //Reload all pictures from file If you do _device.RestoreAllSurfaces(), wouldn't that reload everything for you? It doesn't make sense to me that you'd still have to reload the graphics. If that's the case, then using RestoreAllSurfaces seems rather useless. Am I missing something? EDIT: I tried the code and it works. Thanks for that. I'm still confused as to why I'd need to reload the pictures though. Edited October 18, 2003 by wyrd Quote Gamer extraordinaire. Programmer wannabe.
*Experts* mutant Posted October 18, 2003 *Experts* Posted October 18, 2003 The pictures should be restrored for you with the surface. Quote
wyrd Posted October 18, 2003 Author Posted October 18, 2003 Hm.. that's what I thought. Thanks. Quote Gamer extraordinaire. Programmer wannabe.
wyrd Posted October 18, 2003 Author Posted October 18, 2003 I didn't like how it automatically "paused" the game when trying to restore surfaces, so I changed the logic.. that way the game is still updated (just not drawn) even while minimized; /// <summary> /// Attempts to restore surfaces if they are not available. /// </summary> private void _restoreSurfaces() { // Surfaces may need to be restored. if (!_surfacesAvailable) { try { _device.RestoreAllSurfaces(); _surfacesAvailable = true; } catch (Exception) { // Ignore errors. } } // Check if surfaces were lost. if (!_device.TestCooperativeLevel()) { _surfacesAvailable = false; } } Quote Gamer extraordinaire. Programmer wannabe.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.