From 63c8c1e862ee7dcd98dfd0d786e65e1b4fa05267 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. Pick-to: 6.7 6.6 Change-Id: I395d247a952f9584122be083ac5ca6a3caddf300 Reviewed-by: Laszlo Agocs --- 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 2909152d4a1..f06d64a2ff8 100644 --- a/src/gui/rhi/qrhid3d12.cpp +++ b/src/gui/rhi/qrhid3d12.cpp @@ -503,8 +503,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) {