Skip to main content
GameDev.net gamedev.net
🔒 Locked

DEVICELOST

Started by STRATERCAS Sep 15, 2005 at 3:49 AM 4 replies 750+ views
Original Post
STRATERCAS
STRATERCAS
How do I get TestCooperativeLevel() to return D3D_OK again? I've tried a bunch of different combinations. What I get with this and everything else I've tried is once TestCooperativeLevel() goes bad it stays bad then from there on out it's releasing and recreating every cycle there after. Originally I did have the tests as the first thing in my cycles it's only like this because just playing with it trying to get it to work. [C++, ALT+TAB Problem];
	
if(d3ddev->Present(NULL,NULL,NULL,NULL) == D3DERR_DEVICELOST)
{
	if(d3ddev->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
	{
		ReleaseSurfaces();
		d3ddev->Reset(&d3dpp);
		LoadSurfaces();
	}
}


[Edited by - STRATERCAS on September 15, 2005 4:35:21 AM]
Armadon
Armadon
Hi there STRATERCAS,
How are you doing?

The Problem
TestCooperativeLevel() never returns D3D_OK

The Solution
Let's first see what needs to be done to reset the device appropriately
DirectX c++ Docs on Lost Devices
Lost Devices

So...
Where do we catch the error code
The Present method of the device throws the D3DERR_DEVICELOST error code.
This means we will have to catch it at our Present Method.
Example:
private : bool deviceLost = false;if(pDevice != null && !deviceLost){   if(pDevice->Present() == D3DERR_DEVICELOST)   {       deviceLost = true;   }}


What do we do now?
Well what we can do is keep on trying to see if the device is still lost by using the TestCooperativeLevel() method
Example:
private void Recover(){    if(pDevice->TestCooperativeLevel() == D3DERR_DEVICELOST)    {         return;    }    else if(pDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)    {         pDevice->Reset();         deviceLost = false;    }}


This is probably very ugly but it just shows what you need to do.
Coming to your specific problem. You might be calling the present method a number of times and the device keeps on failing, You need to give the device time to relax/chill so that it can say... "yes" reset me now thank you ;)

So try the boolean effort and stay away from calling the present method a number of times and only testing once for a DeviceLost error.

How can I fix my code?
Look at the code I provided above and try and follow a similar pattern.

I hope this helps a bit buddy.
Take care.
MasterWorks
MasterWorks
Be sure to check the DEBUG OUTPUT!
Evil Steve
Evil Steve
What do you mean by "it goes bad again"? Are you sure you're releasing your non-managed resources before trying to reset? As MasterWorks said, check the debug output. If you have the debug D3D runtime installed, wit hthe debug output level set to maximum, you'll be given some information when any D3D function fails.
STRATERCAS
STRATERCAS
Ok, now this is what I've tried. I put a MessageBox() of death in there just to see if it's even getting called. How could it not be getting called, it's still getting displayed. It's window is not in focus, but it is getting displayed none the less when I alt tab. When I alt tab it continues to draw to the draw but stuff flickers through the display. Also now that I've put that MessageBox in there I've come to find out that TestCooperativeLevel() Never at anypoint is equaling D3DERR_DEVICELOST or D3DERR_DEVICENOTRESET because if it had ever gotten lost Present() would have set devicelost to false and the function with the MessageBox() would have fired off. It never does.

	if(d3ddev->TestCooperativeLevel() == D3DERR_DEVICELOST)	{                MessageBox(NULL,"", "", MB_OK);		return ;	}		if(d3ddev->TestCooperativeLevel() == D3DERR_DEVICENOTRESET || devicelost == true)	{		MessageBox(NULL,"", "", MB_OK);		ReleaseSurfaces();		d3ddev->Reset(&d3dpp);		LoadSurfaces();		SetFocus(hWnd);		devicelost = false;	}	/////////////////////////////////////////////PRESENT///////////////////////////////////////////	if(d3ddev != NULL && !devicelost)	{		if(d3ddev->Present(NULL,NULL,NULL,NULL) == D3DERR_DEVICELOST)                {                        MessageBox(NULL,"", "", MB_OK);			devicelost = true;                } 	}




Every time I try to run with DirectX debugging just about everything quits working and the only way to stop my computer from choking is to kill the Visual Studio Process because it won't let me kill the program I'm debugging nor will it stop by any other method(stop methods I've coded or any standerd way of killing the program), then at which point I can't see the debugger anymore. My guess is it's because of the very problem I'm trying to fix.


This might be easyer here is a zip of the source:
http://www.everyrpg.com/helpmeplease.zip
The display stuff is in GAMEFUNCTIONS.cpp at the bottom.

[Edited by - STRATERCAS on September 15, 2005 7:57:36 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.