Sign in to follow this  

When losing focus, why can't I reset the d3dDevice?

This topic is 4715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to make my program reset the d3ddevice when it has been alt-tabbed then focused again. heres my code, am I missing anything?
HRESULT isFocus = d3dDevice->TestCooperativeLevel();
if(FAILED(isFocus)) {
	if(isFocus == D3DERR_DEVICENOTRESET) {
		D3DPRESENT_PARAMETERS d3dpp; 
		ZeroMemory(&d3dpp, sizeof(d3dpp));	
		d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
		d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
		d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
		d3dpp.Windowed = FALSE;	
		d3dpp.AutoDepthStencilFormat = D3DFMT_D16;	
		d3dpp.EnableAutoDepthStencil = TRUE;
		d3dpp.BackBufferWidth = width;
		d3dpp.BackBufferHeight = height;
		d3dDevice->Reset(&d3dpp);
	}
} else {
	d3dDevice->Clear(0,0,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0),1.0f,0);
	d3dDevice->BeginScene();
	d3dxFont->DrawText(0,"hello",-1,0,DT_NOCLIP,D3DCOLOR_XRGB(255,255,255));
	d3dDevice->EndScene();
	d3dDevice->Present(0,0,0,0);
}


It won't show the black background or the text. Also what do I put in the GetSwapChain() first parameter? thanks

Share this post


Link to post
Share on other sites
Hi,

Have you checked the return code of Reset()? If it is failing, it will probably give you a hint on what's going wrong.

If Reset() is not failing, then you could try forcing the transforms, render, texture and sampler states as you did when creating the device to make sure the device is in the right state before starting rendering again.

Share this post


Link to post
Share on other sites
You have to free all non-managed textures, vertex buffers, state blocks, etc that are in use, Reset, then recreate those resources. Anything not in POOL_MANAGED needs destroying and recreating. If you use the debug runtimes the output window should list each resource you've missed.

You'll notice the D3D samples all have InvalidateDevice and RestoreDevice member functions. These are for the freeing and recreating of resources. The font system you're using likely has calls for this, if they're necessary.

You should also check for DEVICELOST. In this case you don't reset or render, just sit back and processing more windows messages until you get DEVICENOTRESET. This ensures that you don't suck all the performance away from other apps when you should be in the background, awaiting your turn.

Share this post


Link to post
Share on other sites

Quote:
Original post by WildWest
You also have to handle the lost device for your ID3DXFONT object (also when you use ID3DXSPRITE).


Hey I've looked through the functions of the font, vertex buffer classes and they don't contain any reset function, do I just call their create functions again?

Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by johnnyBravo
What about the vertex and index buffers, how would I reset them?

Thanks

If they aren't in the pools Coder mentioned above, release and re-create them.

Share this post


Link to post
Share on other sites

This topic is 4715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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