Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Gamer extraordinaire. Programmer wannabe.
  • *Experts*
Posted

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

"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
Posted

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. :)

Gamer extraordinaire. Programmer wannabe.
Posted

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?

Gamer extraordinaire. Programmer wannabe.
Posted

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
           }
       }

.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?
Posted (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 by wyrd
Gamer extraordinaire. Programmer wannabe.
Posted

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;
		}
	}

Gamer extraordinaire. Programmer wannabe.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...