From 89e0290d06af703bd42cdd207c9056456a427f37 Mon Sep 17 00:00:00 2001 From: Silent Date: Fri, 4 Sep 2020 23:44:19 +0200 Subject: [PATCH] Fix resource leaks in AutoStagingTexture::EnsureSize and D3D11HostDisplay::DownloadTexture --- src/common/d3d11/staging_texture.cpp | 4 ++-- src/frontend-common/d3d11_host_display.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/d3d11/staging_texture.cpp b/src/common/d3d11/staging_texture.cpp index 148251308..a90a3f365 100644 --- a/src/common/d3d11/staging_texture.cpp +++ b/src/common/d3d11/staging_texture.cpp @@ -84,8 +84,8 @@ bool AutoStagingTexture::EnsureSize(ID3D11DeviceContext* context, u32 width, u32 if (m_texture && m_width >= width && m_height >= height && m_format == format) return true; - ID3D11Device* device; - context->GetDevice(&device); + ComPtr device; + context->GetDevice(device.GetAddressOf()); CD3D11_TEXTURE2D_DESC new_desc(format, width, height, 1, 1, 0, for_uploading ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_STAGING, diff --git a/src/frontend-common/d3d11_host_display.cpp b/src/frontend-common/d3d11_host_display.cpp index b8ec7fe58..80162f505 100644 --- a/src/frontend-common/d3d11_host_display.cpp +++ b/src/frontend-common/d3d11_host_display.cpp @@ -156,15 +156,15 @@ bool D3D11HostDisplay::DownloadTexture(const void* texture_handle, u32 x, u32 y, { ID3D11ShaderResourceView* srv = const_cast(static_cast(texture_handle)); - ID3D11Resource* srv_resource; + ComPtr srv_resource; D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc; - srv->GetResource(&srv_resource); + srv->GetResource(srv_resource.GetAddressOf()); srv->GetDesc(&srv_desc); if (!m_readback_staging_texture.EnsureSize(m_context.Get(), width, height, srv_desc.Format, false)) return false; - m_readback_staging_texture.CopyFromTexture(m_context.Get(), srv_resource, 0, x, y, 0, 0, width, height); + m_readback_staging_texture.CopyFromTexture(m_context.Get(), srv_resource.Get(), 0, x, y, 0, 0, width, height); return m_readback_staging_texture.ReadPixels(m_context.Get(), 0, 0, width, height, out_data_stride / sizeof(u32), static_cast(out_data)); }