   Couple of Direct3D Errors
  I can't figure out what's causing these errors. Any ideas?Direct3D9: (ERROR) :GetClientRect Failed ?Direct3D9: (ERROR) :GetClientRect Failed ?Direct3D9: (ERROR) :BitBlt or StretchBlt failed in Present
  It could help if you tell what method and what interface are related to these errors.You can get a rectangle area on several different direct3D interfaces, such as textures and surfaces (maybe thats it?)Anyway, it is possible you tried to lock a texture that you are not allowed to lock, because its perhaps on a dynamic memory.If you get these errors every time you run the program then you are in a good position, because that means you can detect and fix them.Hope that helps.   ;  I do get these errors each time. The only thing that can possibly be it is my simple rendering routine which doesn't even do anything at the time being. I believe these errors sneak into my output when I close the window, so it might have something to do with that, but I check to make sure the device is still valid before rendering so that should catch it, right?HRESULT SimApp::Render(void){if(d3dDevice == NULL)return E_FAIL;HRESULT hr;hr = d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0xFF000000, 1.0f, 0);if(FAILED(hr))return hr;hr = d3dDevice->BeginScene();if(FAILED(hr))return hr;hr = d3dDevice->EndScene();if(FAILED(hr))return hr;hr = d3dDevice->Present(NULL, NULL, NULL, NULL);if(FAILED(hr))return hr;return S_OK;};  I've narrowed it down a little bit. I get the error when I hit the close button in the top right of the window, but not when I just hit escape. Looking at the code, these two things should behave the same, but apparently not. Can anyone see any problems? Here's the code for the WndProc for my app and the related code.LRESULT SimApp::WndProc(HWND p_hwnd, UINT p_msg, WPARAM p_wparam, LPARAM p_lparam){switch(p_msg){case WM_CLOSE:case WM_DESTROY:case WM_QUIT:mainLoopDone = true;return 0;}return (DefWindowProc(p_hwnd, p_msg, p_wparam, p_lparam));}LRESULT CALLBACK SimApp::StaticWndProc(HWND p_hwnd, UINT p_msg, WPARAM p_wparam, LPARAM p_lparam){SimApp *pParent;if(p_msg == WM_NCCREATE){pParent = (SimApp*)((LPCREATESTRUCT)p_lparam)->lpCreateParams;SetWindowLongPtr(p_hwnd, GWL_USERDATA, (LONG_PTR)pParent);}else{pParent = (SimApp*)GetWindowLongPtr(p_hwnd, GWL_USERDATA);if(!pParent)return DefWindowProc(p_hwnd, p_msg, p_wparam, p_lparam);}return pParent->WndProc(p_hwnd, p_msg, p_wparam, p_lparam);}void SimApp::EndMainLoop(void){mainLoopDone = true;}HRESULT SimApp::MainLoop(HRESULT(*idleFunc)(void)){MSG msg;mainLoopDone = false;HRESULT returningValue = S_OK;while(!mainLoopDone){//update our keyboard input statesmemcpy(keyHeldBuffer, keyDownBuffer, sizeof(keyDownBuffer));HRESULT hr = keyboardDevice->GetDeviceState(sizeof(keyDownBuffer),(LPVOID)&keyDownBuffer);if(FAILED(hr)){returningValue = hr;mainLoopDone = true;}//update our mouse input statesmemcpy(mouseHeldButtons, mouseState.rgbButtons, sizeof(mouseState.rgbButtons));if(mouseDevice->GetDeviceState(sizeof(mouseState),(LPVOID)&mouseState) == DIERR_INPUTLOST)mouseDevice->Acquire();if(idleFunc != NULL){hr = idleFunc();if(FAILED(hr))return hr;}hr = d3dDevice->TestCooperativeLevel();if(SUCCEEDED(hr))hr = Render();if(hr == D3DERR_DEVICELOST || hr == D3DERR_DEVICENOTRESET){if(hr == D3DERR_DEVICELOST)Sleep(500);else if(hr == D3DERR_DEVICENOTRESET)hr = d3dDevice->Reset(&appParameters.d3dParameters);}else if(FAILED(hr)){returningValue = hr;mainLoopDone = true;}//handle Windows messageswhile(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){TranslateMessage(&msg);DispatchMessage(&msg);}}return returningValue;}...HRESULT Idle(){if(app.IsKeyDown(DIK_ESCAPE))app.EndMainLoop();return S_OK;};  This happens when the device window has been destroyed and then you've called Present.Set a breakpoint in your error handler for when Present fails.  When it gets hit, look up the callstack and see how Present got called and if that mainLoopDone flag is set.   ;  I look it up. The mainLoopDone is still set to false. I'm guessing this is because my window is destroyed when I hit the button, but my app doesn't get the message until after it renders the frame. How can I fix this?   