Sign in to follow this  
dist0rted

Problem with my Lost Device handling method (C++)

Recommended Posts

My code doesn't really work at all. I create a full screen application, ALT+TAB out of it, Restore it from the Start Menu, and I get the plain white Win32 Window I created (without Direct3D initiated - which sets the screen black) Alrighty, this code is what I put in my main loop: (After I handle Window input, and before I render anything)
// Handle Lost Device:
hResult = m_pd3dDevice->TestCooperativeLevel();
if (FAILED(hResult))
{
	// Check if Device is Lost:
	if (hResult = D3DERR_DEVICELOST)
	{
		Sleep(100); // Rest the Program for a Bit
	}
	else
	{
		InvalidateDeviceOjbects(); // Shutdown User Defined data in this function
				
		if (m_pd3dDevice->TestCooperativeLevel() == D3DERR_DEVICELOST)
		{
			Sleep(100); // Device is still lost
		}
		else
		{
			RestoreDeviceObjects(); // Re-Init User Data in this Function
		}
	}
}

Share this post


Link to post
Share on other sites
Doesn't look like your reseting the device first, is the m_pd3dDevice->Reset call inside RestoreDeviceObjects()?

Also (hResult = D3DERR_DEVICELOST) is the one = a typo? shouldn't really effect outcome though as it would just execute the else part of the if-else.

Heres the reset code from a project of mine

The m_pCurrentpresentParameters is saved in the class from when D3D is initialized


else if( hr == D3DERR_DEVICENOTRESET )
{
// release all d3dpool_default members before reset
OnDeviceLost();

hr = m_pDevice->Reset(&m_pCurrentpresentParameters);

if( hr == D3D_OK )
{
m_bDeviceLost = false;
// recreate all d3dpool_default members
OnDeviceReset();
}
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this