From 950c61d48bf227d8409ad45459022f44fbe9c43e Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 12 Nov 2024 12:44:57 +0100 Subject: [PATCH] rhi: Do not lose track of swapchains on manual destroy-create Pick-to: 6.8 Change-Id: Ieb1c06c881dff3e1dbd0cff470d5a7c264a20d1d Reviewed-by: Andy Nichols --- src/gui/rhi/qrhid3d12.cpp | 6 +++--- src/gui/rhi/qrhigles2.cpp | 4 +--- src/gui/rhi/qrhimetal.mm | 5 ++--- src/gui/rhi/qrhivulkan.cpp | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/gui/rhi/qrhid3d12.cpp b/src/gui/rhi/qrhid3d12.cpp index eb7318f5b83..be78d532394 100644 --- a/src/gui/rhi/qrhid3d12.cpp +++ b/src/gui/rhi/qrhid3d12.cpp @@ -6779,10 +6779,10 @@ bool QD3D12SwapChain::createOrResize() QDxgiVSyncService::instance()->registerWindow(window); - if (needsRegistration) { + if (needsRegistration || !rhiD->swapchains.contains(this)) rhiD->swapchains.insert(this); - rhiD->registerResource(this); - } + + rhiD->registerResource(this); return true; } diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 53cad2df9d6..b28cde4477e 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -6765,7 +6765,6 @@ void QGles2SwapChain::initSwapChainRenderTarget(QGles2SwapChainRenderTarget *rt) bool QGles2SwapChain::createOrResize() { // can be called multiple times due to window resizes - const bool needsRegistration = !surface || surface != m_window; if (surface && surface != m_window) destroy(); @@ -6798,8 +6797,7 @@ bool QGles2SwapChain::createOrResize() // The only reason to register this fairly fake gl swapchain // object with no native resources underneath is to be able to // implement a safe destroy(). - if (needsRegistration) - rhiD->registerResource(this, false); + rhiD->registerResource(this, false); return true; } diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index 36cfd633a9e..020a63b606c 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -6418,7 +6418,7 @@ bool QMetalSwapChain::createOrResize() // else no destroy(), this is intentional QRHI_RES_RHI(QRhiMetal); - if (needsRegistration) + if (needsRegistration || !rhiD->swapchains.contains(this)) rhiD->swapchains.insert(this); window = m_window; @@ -6540,8 +6540,7 @@ bool QMetalSwapChain::createOrResize() [desc release]; } - if (needsRegistration) - rhiD->registerResource(this); + rhiD->registerResource(this); return true; } diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 659506c12d0..3046e310188 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -8671,7 +8671,7 @@ bool QVkSwapChain::createOrResize() return false; } - if (needsRegistration) + if (needsRegistration || !rhiD->swapchains.contains(this)) rhiD->swapchains.insert(this); if (m_depthStencil && m_depthStencil->sampleCount() != m_sampleCount) {