From 469cfcef5593d73975a077b8d25027ba56ccb955 Mon Sep 17 00:00:00 2001 From: MikaĆ«l Capelle Date: Thu, 31 Dec 2020 11:51:20 +0100 Subject: Tentative fix for crash during large extraction. --- src/installationmanager.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index e9324b41..413f567a 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -186,19 +186,26 @@ bool InstallationManager::extractFiles(QString extractPath, QString title, bool // Cancelling progress only cancel the extraction, we do not force exiting the event-loop: connect(installationProgress, &QProgressDialog::canceled, [this]() { m_ArchiveHandler->cancel(); }); + std::mutex mutex; int currentProgress = 0; QString currentFileName; // The callbacks: - auto progressCallback = [this, ¤tProgress](auto progressType, uint64_t current, uint64_t total) { + auto progressCallback = [this, ¤tProgress, &mutex](auto progressType, uint64_t current, uint64_t total) { if (progressType == Archive::ProgressType::EXTRACTION) { - currentProgress = static_cast(100 * current / total); + { + std::scoped_lock guard(mutex); + currentProgress = static_cast(100 * current / total); + } emit progressUpdate(); } }; - Archive::FileChangeCallback fileChangeCallback = [this, ¤tFileName](auto changeType, std::wstring const& file) { + Archive::FileChangeCallback fileChangeCallback = [this, ¤tFileName, &mutex](auto changeType, std::wstring const& file) { if (changeType == Archive::FileChangeType::EXTRACTION_START) { - currentFileName = QString::fromStdWString(file); + { + std::scoped_lock guard(mutex); + currentFileName = QString::fromStdWString(file); + } emit progressUpdate(); } }; @@ -222,6 +229,7 @@ bool InstallationManager::extractFiles(QString extractPath, QString title, bool while (!futureWatcher.isFinished()) { loop.processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents); + std::scoped_lock guard(mutex); if (currentProgress != installationProgress->value()) { installationProgress->setValue(currentProgress); } -- cgit v1.3.1