From 1dd21a5e4a5360ceac5f549fb613722487bfb4f1 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 4 Jul 2024 16:38:40 +0300 Subject: [PATCH 1/2] fix crash with hash task Signed-off-by: Trial97 --- launcher/modplatform/helpers/HashUtils.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/launcher/modplatform/helpers/HashUtils.cpp b/launcher/modplatform/helpers/HashUtils.cpp index f20af1f09..51789910c 100644 --- a/launcher/modplatform/helpers/HashUtils.cpp +++ b/launcher/modplatform/helpers/HashUtils.cpp @@ -18,8 +18,7 @@ Hasher::Ptr createHasher(QString file_path, ModPlatform::ResourceProvider provid case ModPlatform::ResourceProvider::FLAME: return makeShared(file_path, Algorithm::Murmur2); default: - qCritical() << "[Hashing]" - << "Unrecognized mod platform!"; + qCritical() << "[Hashing]" << "Unrecognized mod platform!"; return nullptr; } } @@ -129,6 +128,10 @@ QString hash(QString fileName, Algorithm type) QFile file(fileName); return hash(&file, type); } +QString hashFile(QString fileName, Algorithm type) +{ + return hash(fileName, type); +} QString hash(QByteArray data, Algorithm type) { @@ -138,7 +141,7 @@ QString hash(QByteArray data, Algorithm type) void Hasher::executeTask() { - m_future = QtConcurrent::run(QThreadPool::globalInstance(), [this]() { return hash(m_path, m_alg); }); + m_future = QtConcurrent::run(QThreadPool::globalInstance(), hashFile, m_path, m_alg); connect(&m_watcher, &QFutureWatcher::finished, this, [this] { if (m_future.isCanceled()) { emitAborted(); From 5d8d1c4b90960e3469bb04e566c79afb513da529 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 4 Jul 2024 16:47:27 +0300 Subject: [PATCH 2/2] transform hashFile to lambda Signed-off-by: Trial97 --- launcher/modplatform/helpers/HashUtils.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/launcher/modplatform/helpers/HashUtils.cpp b/launcher/modplatform/helpers/HashUtils.cpp index 51789910c..a3b8d904c 100644 --- a/launcher/modplatform/helpers/HashUtils.cpp +++ b/launcher/modplatform/helpers/HashUtils.cpp @@ -128,10 +128,6 @@ QString hash(QString fileName, Algorithm type) QFile file(fileName); return hash(&file, type); } -QString hashFile(QString fileName, Algorithm type) -{ - return hash(fileName, type); -} QString hash(QByteArray data, Algorithm type) { @@ -141,7 +137,8 @@ QString hash(QByteArray data, Algorithm type) void Hasher::executeTask() { - m_future = QtConcurrent::run(QThreadPool::globalInstance(), hashFile, m_path, m_alg); + m_future = QtConcurrent::run( + QThreadPool::globalInstance(), [](QString fileName, Algorithm type) { return hash(fileName, type); }, m_path, m_alg); connect(&m_watcher, &QFutureWatcher::finished, this, [this] { if (m_future.isCanceled()) { emitAborted();