From 8757f4a548a8cea690baaffd7becaae27b829563 Mon Sep 17 00:00:00 2001 From: Nemirtingas Date: Mon, 19 Aug 2019 19:51:35 +0200 Subject: [PATCH] Fixed ressource leaks. --- overlay_experimental/DX10_Hook.cpp | 6 ++++-- overlay_experimental/DX11_Hook.cpp | 6 ++++-- overlay_experimental/DX12_Hook.cpp | 5 ++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/overlay_experimental/DX10_Hook.cpp b/overlay_experimental/DX10_Hook.cpp index e4f3a390..f02d5918 100644 --- a/overlay_experimental/DX10_Hook.cpp +++ b/overlay_experimental/DX10_Hook.cpp @@ -89,7 +89,7 @@ void DX10_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain) if (!initialized) { - if (FAILED(pSwapChain->GetDevice(__uuidof(ID3D10Device), (PVOID*)& pDevice))) + if (FAILED(pSwapChain->GetDevice(IID_PPV_ARGS(&pDevice)))) return; ImGui::CreateContext(); @@ -98,12 +98,14 @@ void DX10_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain) ID3D10Texture2D* pBackBuffer; - pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)& pBackBuffer); + pSwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); pDevice->CreateRenderTargetView(pBackBuffer, NULL, &mainRenderTargetView); pBackBuffer->Release(); ImGui_ImplDX10_Init(pDevice); + pDevice->Release(); + initialized = true; } diff --git a/overlay_experimental/DX11_Hook.cpp b/overlay_experimental/DX11_Hook.cpp index 9c65e16e..3ebfcab5 100644 --- a/overlay_experimental/DX11_Hook.cpp +++ b/overlay_experimental/DX11_Hook.cpp @@ -12,7 +12,7 @@ DX11_Hook* DX11_Hook::_inst = nullptr; HRESULT GetDeviceAndCtxFromSwapchain(IDXGISwapChain* pSwapChain, ID3D11Device** ppDevice, ID3D11DeviceContext** ppContext) { - HRESULT ret = pSwapChain->GetDevice(__uuidof(ID3D11Device), (PVOID*)ppDevice); + HRESULT ret = pSwapChain->GetDevice(IID_PPV_ARGS(ppDevice)); if (SUCCEEDED(ret)) (*ppDevice)->GetImmediateContext(ppContext); @@ -111,12 +111,14 @@ void DX11_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain) ID3D11Texture2D* pBackBuffer; - pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)& pBackBuffer); + pSwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); pDevice->CreateRenderTargetView(pBackBuffer, NULL, &mainRenderTargetView); pBackBuffer->Release(); ImGui_ImplDX11_Init(pDevice, pContext); + pDevice->Release(); + initialized = true; } diff --git a/overlay_experimental/DX12_Hook.cpp b/overlay_experimental/DX12_Hook.cpp index ef1bac1d..a97ff053 100644 --- a/overlay_experimental/DX12_Hook.cpp +++ b/overlay_experimental/DX12_Hook.cpp @@ -138,7 +138,9 @@ void DX12_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain) } if (!SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, pCmdAlloc, NULL, IID_PPV_ARGS(&pCmdList)))) { - + pCmdAlloc->Release(); + pDescriptorHeap->Release(); + pDevice->Release(); return; } @@ -150,6 +152,7 @@ void DX12_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain) pDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), pDescriptorHeap->GetGPUDescriptorHandleForHeapStart()); + pCmdList->Release(); pCmdAlloc->Release(); pDescriptorHeap->Release(); pDevice->Release();