From 758e249f67a571e166124c78391eddef8b2ab706 Mon Sep 17 00:00:00 2001 From: Vladimir Belyavsky Date: Tue, 3 Oct 2023 19:31:08 +0300 Subject: [PATCH] QRhiD3D11: do not crash on endFrame() when IDXGISwapChain is null There are reports on crashes in QRhiD3D11::endFrame() due to nullptr access to swapChain (IDXGISwapChain). It's still not clear under what conditions this might happen, but we can make a speculative fix (as a last chance) by simply adding a check that the swapChain is not null. Instead of crashing in such cases, we will warn now and return QRhi::FrameOpError, similar to the case when IDXGISwapChain::Present() failed. Task-number: QTBUG-109708 Pick-to: 6.5 Change-Id: I2b0430347a229a618176a38ce3dc9c6e5a33a60c Reviewed-by: Laszlo Agocs (cherry picked from commit 2581bed66be114ae106696a0321f99fba1c4d6f9) Reviewed-by: Qt Cherry-pick Bot --- src/gui/rhi/qrhid3d11.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index ba126049fc6..4df47b5e891 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -1339,6 +1339,10 @@ QRhi::FrameOpResult QRhiD3D11::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrame UINT presentFlags = 0; if (swapChainD->swapInterval == 0 && (swapChainD->swapChainFlags & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING)) presentFlags |= DXGI_PRESENT_ALLOW_TEARING; + if (!swapChainD->swapChain) { + qWarning("Failed to present: IDXGISwapChain is unavailable"); + return QRhi::FrameOpError; + } HRESULT hr = swapChainD->swapChain->Present(swapChainD->swapInterval, presentFlags); if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) { qWarning("Device loss detected in Present()");