From 016bc69bfab23e7f6bc9a1ed12476771702826e7 Mon Sep 17 00:00:00 2001 From: Oliver Dawes Date: Fri, 2 Feb 2024 14:01:22 +0000 Subject: [PATCH] Guard against nullptr cmdAllocators Release call It is possible for a QRhiD3D12 instance to be created and destroyed before the cmdAllocators list is initialized. This change simply guards the cmdAllocators so that Release is only called if the element is not nullptr. For an example of how this can happen see QRhi::create. The QRhiD3D12 is created but may be released immediately if QRhiD3D12::create fails. One way this may happen is if the ID3D12Device is removed but in practice many different errors may cause create to fail. Change-Id: I395d247a952f9584122be083ac5ca6a3caddf300 Reviewed-by: Laszlo Agocs (cherry picked from commit 63c8c1e862ee7dcd98dfd0d786e65e1b4fa05267) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 7ad4db5ee91bdf87cc411e50e6f2068a462f7767) --- src/gui/rhi/qrhid3d12.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gui/rhi/qrhid3d12.cpp b/src/gui/rhi/qrhid3d12.cpp index 5217b98026a..bfc2910ae34 100644 --- a/src/gui/rhi/qrhid3d12.cpp +++ b/src/gui/rhi/qrhid3d12.cpp @@ -453,8 +453,10 @@ void QRhiD3D12::destroy() cbvSrvUavPool.destroy(); for (int i = 0; i < QD3D12_FRAMES_IN_FLIGHT; ++i) { - cmdAllocators[i]->Release(); - cmdAllocators[i] = nullptr; + if (cmdAllocators[i]) { + cmdAllocators[i]->Release(); + cmdAllocators[i] = nullptr; + } } if (fullFenceEvent) {