Click to See Complete Forum and Search --> : direct3d9 OnLostDevice


Feoggou
November 30th, 2009, 03:24 PM
Hi!

I have a fullscreen d3d9 application, with an image displayed on the screen. if I press alt-tab to switch to another window, and then I try to get back to my application, I receive D3DERR_INVALIDCALL error at m_pDevice->Reset(&m_pres_params);

but the problem is that I did not modify m_pres_params structure since the initialization of direct3d (when worked). And I didn't even switch to windowed mode. Can anybody tell me what the problem is and what I can do to solve it?

my code:

main loop:
int CGameApp::Run(void)
{
MSG msg = {0};

while (msg.message != WM_QUIT)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

if (FALSE == IsLostDevice())
{
UpdateScene();
DrawScene();
}
}

return (int)msg.wParam;
}

here, the function IsLostDevice:
bool CGameApp::IsLostDevice(void)
{
HRESULT hr = m_pDevice->TestCooperativeLevel();

if (hr == D3DERR_DEVICELOST)
{
Sleep(20);
return true;
}

if (hr == D3DERR_DRIVERINTERNALERROR) D3DErrorMessage(hr);

if (hr == D3DERR_DEVICENOTRESET)
{
OnLostDevice();//here I call OnLost on the sprite
HRESULT hr = m_pDevice->Reset(&m_pres_params);
if (hr != D3D_OK) D3DErrorMessage(hr);
OnResetDevice();//here I call OnReset on the sprite
return false;
}

return false;
}

and here is how I initialized present parameters:
ZeroMemory(&m_pres_params, sizeof(m_pres_params));

m_pres_params.BackBufferWidth = m_nWidth;//that is, 800
m_pres_params.BackBufferHeight = m_nHeight;//that is, 600
m_pres_params.BackBufferFormat = D3DFMT_X8R8G8B8;
m_pres_params.BackBufferCount = 1;
m_pres_params.MultiSampleType = D3DMULTISAMPLE_NONE;
m_pres_params.MultiSampleQuality = 0;
m_pres_params.SwapEffect = D3DSWAPEFFECT_DISCARD;
m_pres_params.hDeviceWindow = m_hWnd;
m_pres_params.Windowed = bWindowed;
m_pres_params.EnableAutoDepthStencil = true;
m_pres_params.AutoDepthStencilFormat = D3DFMT_D24S8;
m_pres_params.Flags = 0;
m_pres_params.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;

can anybody please help me?