From e000ee01169f735b0ddc91553b42ff3a857e9b9b Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 28 Nov 2017 10:48:01 +0100 Subject: [PATCH] Examples: DirectX9: Handle loss of D3D9 device (D3DERR_DEVICELOST). (#1464) --- examples/directx9_example/main.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index 5a5c0d19..30c820ef 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -154,7 +154,15 @@ int main(int, char**) ImGui::Render(); g_pd3dDevice->EndScene(); } - g_pd3dDevice->Present(NULL, NULL, NULL, NULL); + HRESULT result = g_pd3dDevice->Present(NULL, NULL, NULL, NULL); + + // Handle loss of D3D9 device + if (result == D3DERR_DEVICELOST && g_pd3dDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET) + { + ImGui_ImplDX9_InvalidateDeviceObjects(); + g_pd3dDevice->Reset(&g_d3dpp); + ImGui_ImplDX9_CreateDeviceObjects(); + } } ImGui_ImplDX9_Shutdown();