From a7278cdab198dd690d506c9ef1a59bf633fbf1d2 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 24 Jun 2023 12:35:31 +0200 Subject: [PATCH] [dxgi] Do not interact with other DXGI objects during swapchain destruction This trips up Stalker Anomaly for some reason, but initializing an output is not meaningful anyway in this situation since we either know the output in question already, or we don't and it cannot be in a non-default state. Closes #3531. --- src/dxgi/dxgi_swapchain.cpp | 2 +- src/util/com/com_object.h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/dxgi/dxgi_swapchain.cpp b/src/dxgi/dxgi_swapchain.cpp index adfa667e..60ae6bf8 100644 --- a/src/dxgi/dxgi_swapchain.cpp +++ b/src/dxgi/dxgi_swapchain.cpp @@ -838,7 +838,7 @@ namespace dxvk { HRESULT hr = m_monitorInfo->AcquireMonitorData(hMonitor, ppData); - if (FAILED(hr)) { + if (FAILED(hr) && HasLiveReferences()) { // We may need to initialize a DXGI output to populate monitor data. // If acquiring monitor data has failed previously, do not try again. if (hMonitor == m_monitor && !m_monitorHasOutput) diff --git a/src/util/com/com_object.h b/src/util/com/com_object.h index 75188d5c..7468bc06 100644 --- a/src/util/com/com_object.h +++ b/src/util/com/com_object.h @@ -68,10 +68,14 @@ namespace dxvk { } } - ULONG GetPrivateRefCount() { + ULONG GetPrivateRefCount() const { return m_refPrivate.load(); } - + + bool HasLiveReferences() const { + return bool(m_refCount.load() | m_refPrivate.load()); + } + protected: std::atomic m_refCount = { 0ul };