From b2c97f2cf388fb08a81dddee45a41a359c617295 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Thu, 17 Aug 2023 18:04:41 +0100 Subject: [PATCH] Use QPointer to track live capture windows during Shutdown The save capture modal message box could process messages which could delete a LiveCapture, the pointer had already been copied into a local list, then try to use deleted memory. --- qrenderdoc/Windows/MainWindow.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/qrenderdoc/Windows/MainWindow.cpp b/qrenderdoc/Windows/MainWindow.cpp index 082336cc8..fec824c79 100644 --- a/qrenderdoc/Windows/MainWindow.cpp +++ b/qrenderdoc/Windows/MainWindow.cpp @@ -2942,14 +2942,22 @@ void MainWindow::closeEvent(QCloseEvent *event) bool noToAll = false; - QList liveCaptures = m_LiveCaptures; + QList> liveCaptures; int unsavedCaps = 0; - for(LiveCapture *live : liveCaptures) - unsavedCaps += live->unsavedCaptureCount(); - - for(LiveCapture *live : liveCaptures) + for(QPointer live : m_LiveCaptures) { + unsavedCaps += live->unsavedCaptureCount(); + liveCaptures.append(live); + } + + for(QPointer live : liveCaptures) + { + // The live capture could be deleted during this loop via the save capture modal message box + // message pump of an earlier live capture + if(live.isNull()) + continue; + // if the user previously selected 'no to all' in the save prompts below, apply that to all // subsequent live captures by skipping the check and unconditionally cleaning all captures if(!noToAll)