1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-12 13:08:50 +01:00

[dxgi] Work around swapchain use-after-free bugs

Affects Divinity: Original Sin Enhanced Edition. Requires Wine hack to
delay memory deallocation to not crash during resolution changes.
This commit is contained in:
Philip Rebohle 2022-03-22 20:36:49 +01:00
parent 586948df1e
commit 8823e4bb3d
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99

View File

@ -16,16 +16,28 @@ namespace dxvk {
} }
ULONG STDMETHODCALLTYPE AddRef() { ULONG STDMETHODCALLTYPE AddRef() {
return m_dispatch->AddRef(); if (likely(m_dispatch != nullptr))
return m_dispatch->AddRef();
return 0;
} }
ULONG STDMETHODCALLTYPE Release() { ULONG STDMETHODCALLTYPE Release() {
ULONG refCount = m_dispatch->Release(); if (likely(m_dispatch != nullptr)) {
ULONG refCount = m_dispatch->Release();
if (unlikely(!refCount)) if (unlikely(!refCount)) {
delete this; // Clear the underlying swap chain pointer. Helps in
// use-after-free situations encountered in Divinity
// Original Sin Enhanced Edition.
m_dispatch = nullptr;
delete this;
}
return refCount; return refCount;
}
return ~0u;
} }
HRESULT STDMETHODCALLTYPE QueryInterface( HRESULT STDMETHODCALLTYPE QueryInterface(
@ -114,7 +126,16 @@ namespace dxvk {
HRESULT STDMETHODCALLTYPE GetFullscreenState( HRESULT STDMETHODCALLTYPE GetFullscreenState(
BOOL* pFullscreen, BOOL* pFullscreen,
IDXGIOutput** ppTarget) final { IDXGIOutput** ppTarget) final {
return m_dispatch->GetFullscreenState(pFullscreen, ppTarget); if (likely(m_dispatch != nullptr))
return m_dispatch->GetFullscreenState(pFullscreen, ppTarget);
if (pFullscreen)
*pFullscreen = FALSE;
if (ppTarget)
*ppTarget = nullptr;
return S_OK;
} }
HRESULT STDMETHODCALLTYPE GetFullscreenDesc( HRESULT STDMETHODCALLTYPE GetFullscreenDesc(