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.6
Change-Id: I395d247a952f9584122be083ac5ca6a3caddf300
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
(cherry picked from commit 63c8c1e862ee7dcd98dfd0d786e65e1b4fa05267)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Oliver Dawes 2024-02-02 14:01:22 +00:00 committed by Qt Cherry-pick Bot
parent 7c0ca6e3c9
commit 7ad4db5ee9

View File

@ -509,9 +509,11 @@ void QRhiD3D12::destroy()
cbvSrvUavPool.destroy();
for (int i = 0; i < QD3D12_FRAMES_IN_FLIGHT; ++i) {
if (cmdAllocators[i]) {
cmdAllocators[i]->Release();
cmdAllocators[i] = nullptr;
}
}
if (fullFenceEvent) {
CloseHandle(fullFenceEvent);