From 6d5482874c751111b1775b147483fe7cc40992d3 Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Tue, 11 Jul 2023 21:16:40 +0300 Subject: [PATCH] [d3d8] Ensure all references are cleared before d3d9 device reset --- src/d3d8/d3d8_device.cpp | 11 ++++++----- src/d3d8/d3d8_device.h | 8 ++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/d3d8/d3d8_device.cpp b/src/d3d8/d3d8_device.cpp index c3ad13965589..b39288f519dd 100644 --- a/src/d3d8/d3d8_device.cpp +++ b/src/d3d8/d3d8_device.cpp @@ -53,10 +53,8 @@ namespace dxvk { m_bridge->SetAPIName("D3D8"); - m_textures.fill(nullptr); - m_streams.fill(D3D8VBO()); - ResetState(); + RegenBackBuffersAndAutoDepthStencil(); if (m_d3d8Options.batching) m_batcher = new D3D8Batcher(this, GetD3D9()); @@ -214,14 +212,16 @@ namespace dxvk { // Resetting implicitly ends scenes started by BeginScene GetD3D9()->EndScene(); + m_presentParams = *pPresentationParameters; + ResetState(); + d3d9::D3DPRESENT_PARAMETERS params = ConvertPresentParameters9(pPresentationParameters); HRESULT res = GetD3D9()->Reset(¶ms); if (FAILED(res)) return res; - m_presentParams = *pPresentationParameters; - ResetState(); + RegenBackBuffersAndAutoDepthStencil(); return res; } @@ -970,6 +970,7 @@ namespace dxvk { D3D8StateBlock* block = reinterpret_cast(Token); m_stateBlocks.erase(block); + delete block; return D3D_OK; } diff --git a/src/d3d8/d3d8_device.h b/src/d3d8/d3d8_device.h index 33ea2bbc1889..e053d204caf4 100644 --- a/src/d3d8/d3d8_device.h +++ b/src/d3d8/d3d8_device.h @@ -385,13 +385,17 @@ namespace dxvk { m_backBuffers.clear(); m_backBuffers.resize(m_presentParams.BackBufferCount); + + m_autoDepthStencil = nullptr; + } + + inline void RegenBackBuffersAndAutoDepthStencil() { for (UINT i = 0; i < m_presentParams.BackBufferCount; i++) { Com pSurface9; GetD3D9()->GetBackBuffer(0, i, d3d9::D3DBACKBUFFER_TYPE_MONO, &pSurface9); m_backBuffers[i] = new D3D8Surface(this, std::move(pSurface9)); } - - m_autoDepthStencil = nullptr; + Com pStencil9 = nullptr; GetD3D9()->GetDepthStencilSurface(&pStencil9); m_autoDepthStencil = new D3D8Surface(this, std::move(pStencil9));