From 42a22dd4bb491933a15ea601eee5fa1bb816a40a Mon Sep 17 00:00:00 2001 From: Nemirtingas Date: Wed, 21 Aug 2019 21:52:08 +0200 Subject: [PATCH] Don't free objects with shutdown Some games don't like to free the DX objects after the game has shut down. --- overlay_experimental/DX10_Hook.cpp | 12 +++++++++++- overlay_experimental/DX11_Hook.cpp | 13 ++++++++++++- overlay_experimental/DX12_Hook.cpp | 14 +++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/overlay_experimental/DX10_Hook.cpp b/overlay_experimental/DX10_Hook.cpp index 8ce5dfe4..ceba0e64 100644 --- a/overlay_experimental/DX10_Hook.cpp +++ b/overlay_experimental/DX10_Hook.cpp @@ -194,7 +194,17 @@ DX10_Hook::~DX10_Hook() { PRINT_DEBUG("DX10 Hook removed\n"); - resetRenderState(); + if (initialized) + { + mainRenderTargetView->Release(); + + //ImGui_ImplDX10_Shutdown(); + ImGui_ImplDX10_InvalidateDeviceObjects(); + Windows_Hook::Inst().resetRenderState(); + ImGui::DestroyContext(); + + initialized = false; + } FreeLibrary(reinterpret_cast(_library)); diff --git a/overlay_experimental/DX11_Hook.cpp b/overlay_experimental/DX11_Hook.cpp index e225b073..5e5c1972 100644 --- a/overlay_experimental/DX11_Hook.cpp +++ b/overlay_experimental/DX11_Hook.cpp @@ -212,7 +212,18 @@ DX11_Hook::~DX11_Hook() { PRINT_DEBUG("DX11 Hook removed\n"); - resetRenderState(); + if (initialized) + { + mainRenderTargetView->Release(); + pContext->Release(); + + //ImGui_ImplDX11_Shutdown(); + ImGui_ImplDX11_InvalidateDeviceObjects(); + Windows_Hook::Inst().resetRenderState(); + ImGui::DestroyContext(); + + initialized = false; + } FreeLibrary(reinterpret_cast(_library)); diff --git a/overlay_experimental/DX12_Hook.cpp b/overlay_experimental/DX12_Hook.cpp index bd1aa1ee..edb85f8e 100644 --- a/overlay_experimental/DX12_Hook.cpp +++ b/overlay_experimental/DX12_Hook.cpp @@ -243,7 +243,19 @@ DX12_Hook::~DX12_Hook() { PRINT_DEBUG("DX12 Hook removed\n"); - resetRenderState(); + if (initialized) + { + pCmdAlloc->Release(); + pCmdList->Release(); + pDescriptorHeap->Release(); + + //ImGui_ImplDX12_Shutdown(); + ImGui_ImplDX12_InvalidateDeviceObjects(); + Windows_Hook::Inst().resetRenderState(); + ImGui::DestroyContext(); + + initialized = false; + } FreeLibrary(reinterpret_cast(_library));