Code:
while (m_gameActive)
{
HRESULT hr = pDevice->TestCooperativeLevel();
if (hr == D3D_OK)
{
Render();
}
else if (hr == D3DERR_DEVICELOST)
{
OnLostDevice();
}
else if (hr == D3DERR_DEVICENOTRESET)
{
OnResetDevice();
}
}
Things you lose in lost device conditions:
- ID3DXFont - you must call it's On[Lost/Reset]Device functions.
- All resources using the D3DPOOL_DEFAULT memory pool. These must be recreated. Render target textures fall into this category since they must use D3DPOOL_DEFAULT. But this applies to all resources in Direct3D
- All IDirect3DStateBlock(s) will be released by the device (no need to call release()). These must be-recreated inside of OnResetDevice().
- ID3DXEffect(s) - must call their associated On[Lost/Reset]Device functions
- DirectInput keyboard - May have to re-acquire the keyboard
- If you are using CD3DFont you must call it's associated On[Lost/ResetDevice] functions
- Any swap chains created with CreateAdditionalSwapChain()
If most of your resources use D3DPOOL_MANAGED (which they should) it's not that difficult to put into your system. As an example my system can both respond to a lost device and come back as well as switch from windowed mode to full-screen mode and back on the fly.