Browse Source

Examples: DirectX9/10/11: Taking reference to device + subsequent merge of this in docking will fix DX9 issue #2524

omar 6 years ago
parent
commit
d88121ff5b
3 changed files with 8 additions and 4 deletions
  1. 2 1
      examples/imgui_impl_dx10.cpp
  2. 4 2
      examples/imgui_impl_dx11.cpp
  3. 2 1
      examples/imgui_impl_dx9.cpp

+ 2 - 1
examples/imgui_impl_dx10.cpp

@@ -500,6 +500,7 @@ bool    ImGui_ImplDX10_Init(ID3D10Device* device)
             }
     if (pDXGIDevice) pDXGIDevice->Release();
     if (pDXGIAdapter) pDXGIAdapter->Release();
+    g_pd3dDevice->AddRef();
 
     return true;
 }
@@ -508,7 +509,7 @@ void ImGui_ImplDX10_Shutdown()
 {
     ImGui_ImplDX10_InvalidateDeviceObjects();
     if (g_pFactory) { g_pFactory->Release(); g_pFactory = NULL; }
-    g_pd3dDevice = NULL;
+    if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
 }
 
 void ImGui_ImplDX10_NewFrame()

+ 4 - 2
examples/imgui_impl_dx11.cpp

@@ -508,6 +508,8 @@ bool    ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_co
             }
     if (pDXGIDevice) pDXGIDevice->Release();
     if (pDXGIAdapter) pDXGIAdapter->Release();
+    g_pd3dDevice->AddRef();
+    g_pd3dDeviceContext->AddRef();
 
     return true;
 }
@@ -516,8 +518,8 @@ void ImGui_ImplDX11_Shutdown()
 {
     ImGui_ImplDX11_InvalidateDeviceObjects();
     if (g_pFactory) { g_pFactory->Release(); g_pFactory = NULL; }
-    g_pd3dDevice = NULL;
-    g_pd3dDeviceContext = NULL;
+    if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
+    if (g_pd3dDeviceContext) { g_pd3dDeviceContext->Release(); g_pd3dDeviceContext = NULL; }
 }
 
 void ImGui_ImplDX11_NewFrame()

+ 2 - 1
examples/imgui_impl_dx9.cpp

@@ -219,13 +219,14 @@ bool ImGui_ImplDX9_Init(IDirect3DDevice9* device)
     io.BackendRendererName = "imgui_impl_dx9";
 
     g_pd3dDevice = device;
+    g_pd3dDevice->AddRef();
     return true;
 }
 
 void ImGui_ImplDX9_Shutdown()
 {
     ImGui_ImplDX9_InvalidateDeviceObjects();
-    g_pd3dDevice = NULL;
+    if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
 }
 
 static bool ImGui_ImplDX9_CreateFontsTexture()