From 427e706a40261d78f4dc3d7a0d263a0b7b79013b Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 2 Sep 2024 21:50:42 +0200 Subject: [PATCH] [util,d3d11] Be more robust against use-after-free Sims 4 binds an SRV after destroying it, so we need to ensure our internal view pointers are null or we'll create a problem otherwise. --- src/d3d11/d3d11_view_dsv.cpp | 1 + src/d3d11/d3d11_view_rtv.cpp | 1 + src/d3d11/d3d11_view_srv.cpp | 1 + src/d3d11/d3d11_view_uav.cpp | 1 + src/util/com/com_pointer.h | 1 + src/util/rc/util_rc_ptr.h | 1 + 6 files changed, 6 insertions(+) diff --git a/src/d3d11/d3d11_view_dsv.cpp b/src/d3d11/d3d11_view_dsv.cpp index c444d864..e76d8895 100644 --- a/src/d3d11/d3d11_view_dsv.cpp +++ b/src/d3d11/d3d11_view_dsv.cpp @@ -106,6 +106,7 @@ namespace dxvk { D3D11DepthStencilView::~D3D11DepthStencilView() { ResourceReleasePrivate(m_resource); + m_resource = nullptr; } diff --git a/src/d3d11/d3d11_view_rtv.cpp b/src/d3d11/d3d11_view_rtv.cpp index f8b58f90..471f4b41 100644 --- a/src/d3d11/d3d11_view_rtv.cpp +++ b/src/d3d11/d3d11_view_rtv.cpp @@ -116,6 +116,7 @@ namespace dxvk { D3D11RenderTargetView::~D3D11RenderTargetView() { ResourceReleasePrivate(m_resource); + m_resource = nullptr; } diff --git a/src/d3d11/d3d11_view_srv.cpp b/src/d3d11/d3d11_view_srv.cpp index 2b2f5520..3970cb2c 100644 --- a/src/d3d11/d3d11_view_srv.cpp +++ b/src/d3d11/d3d11_view_srv.cpp @@ -183,6 +183,7 @@ namespace dxvk { D3D11ShaderResourceView::~D3D11ShaderResourceView() { ResourceReleasePrivate(m_resource); + m_resource = nullptr; } diff --git a/src/d3d11/d3d11_view_uav.cpp b/src/d3d11/d3d11_view_uav.cpp index 9f1c2c00..96de3df2 100644 --- a/src/d3d11/d3d11_view_uav.cpp +++ b/src/d3d11/d3d11_view_uav.cpp @@ -129,6 +129,7 @@ namespace dxvk { D3D11UnorderedAccessView::~D3D11UnorderedAccessView() { ResourceReleasePrivate(m_resource); + m_resource = nullptr; } diff --git a/src/util/com/com_pointer.h b/src/util/com/com_pointer.h index c81fae24..0aad347d 100644 --- a/src/util/com/com_pointer.h +++ b/src/util/com/com_pointer.h @@ -96,6 +96,7 @@ namespace dxvk { ~Com() { this->decRef(); + m_ptr = nullptr; } T* operator -> () const { diff --git a/src/util/rc/util_rc_ptr.h b/src/util/rc/util_rc_ptr.h index bc4b4bdd..d6c0c363 100644 --- a/src/util/rc/util_rc_ptr.h +++ b/src/util/rc/util_rc_ptr.h @@ -86,6 +86,7 @@ namespace dxvk { ~Rc() { this->decRef(); + m_object = nullptr; } T& operator * () const { return *m_object; }