Hullo hullo,
After doing an Alt-Tab out of a DX program while its running, and then trying to refocus back onto the window, DX likes to do some crazy things and some resources need to be reset.
The two I've learned this about so far are the ID3DXFont object and the camera; which need to be released/reset. The code I have for this looks like this:
Code:
bool cDX::D3DHasFocus(void)
{
long Attempt;
Attempt = D3DDevice->TestCooperativeLevel();
if(SUCCEEDED(Attempt))
return true;
if(Attempt == D3DERR_DEVICELOST)
{
Font->LostFocus();
}
else if(Attempt == D3DERR_DEVICENOTRESET)
{
if(SUCCEEDED(D3DDevice->Reset(&PP)))
{
Font->GotFocus();
Camera->Init(D3DDevice, (float)PP.BackBufferWidth, (float)PP.BackBufferHeight);
}
}
return false;
}
//Note, Position, Look, Up, and Right are initialised in the Class constructor to avoid them
//being reset each to their hard-coded values upon re-focussing.
void cCamera::Init(IDirect3DDevice9* D3DDevice, float ScreenWidth, float ScreenHeight)
{
float AspectRatio = (ScreenWidth / ScreenHeight);
D3DXMATRIX matView;
D3DXMATRIX matLens;
D3DXMATRIX matWorld;
D3DXMatrixLookAtLH(&matView, &Position, &Look, &Up);
D3DDevice->SetTransform(D3DTS_VIEW, &matView);
D3DXMatrixPerspectiveFovLH(&matLens, D3DX_PI/4, AspectRatio, 1.0f, 2000.0f);
D3DDevice->SetTransform(D3DTS_PROJECTION, &matLens);
D3DXMatrixIdentity(&matWorld);
D3DDevice->SetTransform(D3DTS_WORLD, &matWorld);
}
void cFont::LostFocus(void)
{
FontDevice->OnLostDevice();
}
void cFont::GotFocus(void)
{
FontDevice->OnResetDevice();
}
Now, the problem I'm having is with my meshes. If I Alt-Tab out, then open the window back up, my program is telling me I'm still rendering 125 objects, but anything that WAS being rendered beforehand just isn't anymore.
I'm assuming the problem lies somewhere in having to release/reset an object related to these meshes. But I don't really see anything too unique to my mesh class (it consists of a D3DDevice passed from my DX class, but I doubt it has anything to do with that since it's always pointing to the same thing).
So I guess I'm just wondering what exactly has to be reset in order to render these meshes again. Any help is appreciated.