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);
}
When losing focus, why can't I reset the d3dDevice?
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?
It won't show the black background or the text.
Also what do I put in the GetSwapChain() first parameter?
thanks
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.
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.
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.
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.
Quote:Original post by johnnyBravo
do you mean any resources not created with the POOL_MANAGED flag?
D3DPOOL_MANAGAED, D3DPOOL_SYSTEMMEM and D3DPOOL_SCRATCH aren't lost.
You also have to handle the lost device for your ID3DXFONT object (also when you use ID3DXSPRITE).
Quote:Original post by WildWest
You also have to handle the lost device for your ID3DXFONT object (also when you use ID3DXSPRITE).
no wonder its crashing!
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement