From 4190b81431d10cd5316df547aabcc989c3613e30 Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Wed, 17 Jul 2019 10:10:51 +0100 Subject: [PATCH] Add an early-out for non-zero internal reference count --- src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index 235057872..f7ba43a62 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -5577,10 +5577,15 @@ ULONG WINAPI XTL::EMUPATCH(D3DResource_Release) // Was the Xbox resource freed? if (uRet == 0) { // We should free any variables storing the resource when freed - // HACK: For now, we skip the release and issue a LOG_TEST_CASE + // HACK: For now, we skip the release when the resource has a non-zero internal ref count + // We also skip the release if we still have a cached variable containing this value // This is a (small) memory leak, but prevents incorrectly freeing an in-use resource - // This is a *temporary* work around until solving - // https://github.com/Cxbx-Reloaded/Cxbx-Reloaded/issues/1665 + // This is a *temporary* work around until solving https://github.com/Cxbx-Reloaded/Cxbx-Reloaded/issues/1665 + if ((pThis->Common & X_D3DCOMMON_INTREFCOUNT_MASK) != 0) { + LOG_TEST_CASE("Skipping Release of resource with a non-zero internal reference count"); + RETURN(uRet); + } + if (pThis == g_pXboxRenderTarget) { LOG_TEST_CASE("Skipping release of active Xbox Render Target"); RETURN(uRet);