Sign in to follow this  
atair

Calls to GetBackBuffer fail after Resetting Device

Recommended Posts

Hi! I've written a little test-app because i need to rewrite a larger one to correctly handle lost devices. The test-app does nothing more than render a black fullscreen. I've now encountered the following problem: Everything works fine (which is not a problem :D ) until i put in the following lines:
IDirect3DSurface9 *bb;
m_pD3DDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &bb);
With those, after minimizing the app and maximizing again only a default windows-window with white background is rendered, the window seems to be processing messages and is not frozen, but the black screen is no longer rendered. Here is the code that handles the lost devices & render the scene:
void Render()
{
	HRESULT hr = m_pD3DDevice->TestCooperativeLevel();
	if( hr != D3D_OK )
	{
		if( hr == D3DERR_DEVICELOST )
			Sleep(50);
		else if( hr == D3DERR_DEVICENOTRESET )
		{
			// d3dpp are the present_params used to create the device
			m_pD3DDevice->Reset(&d3dpp);
		}
	}

	// next 2 lines are the problem
	// need that later to change render targets
	IDirect3DSurface9 *bb;
	m_pD3DDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &bb);

	m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0,0,0,0), 0.0f, 0);
	m_pD3DDevice->BeginScene();
	m_pD3DDevice->EndScene();
	m_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
Any help would be greatly appreciated, and should you need any more code please ask.

Share this post


Link to post
Share on other sites
You need to Release() the backbuffer once you're done with the pointer from GetBackBuffer().

If you don't, then the backbuffer will still be referenced, and D3D won't be able to reset the device.

I'd advise using the debug runtimes (Start menu -> DirectX SDK -> DirectX Utilities -> DirectX Control Panel, select "Use Debug Version" for all tabs, and put the Debug Output Level up to maximum), since then you'll get useful error information spat out into your IDEs debug output window when D3D calls fail.

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