From 17a7f352b519a9fd850d29dcef92d4bd64ff34c1 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 19 Apr 2018 17:23:43 +0200 Subject: [PATCH] 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. --- examples/imgui_impl_dx10.cpp | 6 ++++++ examples/imgui_impl_dx11.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index 476984039..9d5972461 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -23,6 +23,7 @@ #include "imgui_impl_dx10.h" // DirectX +#include #include #include #include @@ -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(); } diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp index f8971bc66..9f5b38249 100644 --- a/examples/imgui_impl_dx11.cpp +++ b/examples/imgui_impl_dx11.cpp @@ -22,6 +22,7 @@ #include "imgui_impl_dx11.h" // DirectX +#include #include #include @@ -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(); }