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,18 +16,30 @@ namespace dxvk {
}
ULONG STDMETHODCALLTYPE AddRef() {
if (likely(m_dispatch != nullptr))
return m_dispatch->AddRef();
return 0;
}
ULONG STDMETHODCALLTYPE Release() {
if (likely(m_dispatch != nullptr)) {
ULONG refCount = m_dispatch->Release();
if (unlikely(!refCount))
if (unlikely(!refCount)) {
// 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 ~0u;
}
HRESULT STDMETHODCALLTYPE QueryInterface(
REFIID riid,
void** ppvObject) final {
@ -114,7 +126,16 @@ namespace dxvk {
HRESULT STDMETHODCALLTYPE GetFullscreenState(
BOOL* pFullscreen,
IDXGIOutput** ppTarget) final {
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(