Browse Source

Viewporrt. Examples: DirectX10,11: Make the platform SetWindowSize handler not crash on failure to resize, which could happen (rarely) on invalid data or bug in the code.

omar 7 years ago
parent
commit
17a7f352b5
2 changed files with 12 additions and 0 deletions
  1. 6 0
      examples/imgui_impl_dx10.cpp
  2. 6 0
      examples/imgui_impl_dx11.cpp

+ 6 - 0
examples/imgui_impl_dx10.cpp

@@ -23,6 +23,7 @@
 #include "imgui_impl_dx10.h"
 
 // DirectX
+#include <stdio.h>
 #include <d3d10_1.h>
 #include <d3d10.h>
 #include <d3dcompiler.h>
@@ -581,6 +582,11 @@ static void ImGui_ImplDX10_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
         ID3D10Texture2D* pBackBuffer = NULL;
         data->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0);
         data->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
+        if (pBackBuffer == NULL)
+        {
+            fprintf(stderr, "ImGui_ImplDX10_SetWindowSize() can't created buffers.\n");
+            return;
+        }
         g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &data->RTView);
         pBackBuffer->Release();
     }

+ 6 - 0
examples/imgui_impl_dx11.cpp

@@ -22,6 +22,7 @@
 #include "imgui_impl_dx11.h"
 
 // DirectX
+#include <stdio.h>
 #include <d3d11.h>
 #include <d3dcompiler.h>
 
@@ -588,6 +589,11 @@ static void ImGui_ImplDX11_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
         ID3D11Texture2D* pBackBuffer = NULL;
         data->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0);
         data->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
+        if (pBackBuffer == NULL)
+        {
+            fprintf(stderr, "ImGui_ImplDX11_SetWindowSize() can't created buffers.\n");
+            return;
+        }
         g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &data->RTView);
         pBackBuffer->Release();
     }