From 001bbef9eea845ec7b970c73e16d0f129fade18b Mon Sep 17 00:00:00 2001 From: flow Date: Tue, 28 Jun 2022 07:09:58 -0300 Subject: [PATCH] fix: don't use shared_ptr for a background task T_T Signed-off-by: flow --- launcher/modplatform/ModAPI.h | 4 ++-- launcher/modplatform/flame/FlameAPI.cpp | 4 ++-- launcher/modplatform/flame/FlameAPI.h | 2 +- launcher/modplatform/helpers/NetworkModAPI.cpp | 4 ++-- launcher/modplatform/helpers/NetworkModAPI.h | 2 +- launcher/modplatform/modrinth/ModrinthAPI.cpp | 4 ++-- launcher/modplatform/modrinth/ModrinthAPI.h | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/launcher/modplatform/ModAPI.h b/launcher/modplatform/ModAPI.h index 26fe9d026..4114d83ce 100644 --- a/launcher/modplatform/ModAPI.h +++ b/launcher/modplatform/ModAPI.h @@ -75,8 +75,8 @@ class ModAPI { virtual void searchMods(CallerType* caller, SearchArgs&& args) const = 0; virtual void getModInfo(CallerType* caller, ModPlatform::IndexedPack& pack) = 0; - virtual auto getProject(QString addonId, QByteArray* response) const -> NetJob::Ptr = 0; - virtual auto getProjects(QStringList addonIds, QByteArray* response) const -> NetJob::Ptr = 0; + virtual auto getProject(QString addonId, QByteArray* response) const -> NetJob* = 0; + virtual auto getProjects(QStringList addonIds, QByteArray* response) const -> NetJob* = 0; struct VersionSearchArgs { diff --git a/launcher/modplatform/flame/FlameAPI.cpp b/launcher/modplatform/flame/FlameAPI.cpp index 065b4cc28..e40d84f7f 100644 --- a/launcher/modplatform/flame/FlameAPI.cpp +++ b/launcher/modplatform/flame/FlameAPI.cpp @@ -124,7 +124,7 @@ auto FlameAPI::getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::Indexe return ver; } -auto FlameAPI::getProjects(QStringList addonIds, QByteArray* response) const -> NetJob::Ptr +auto FlameAPI::getProjects(QStringList addonIds, QByteArray* response) const -> NetJob* { auto* netJob = new NetJob(QString("Flame::GetProjects"), APPLICATION->network()); @@ -141,7 +141,7 @@ auto FlameAPI::getProjects(QStringList addonIds, QByteArray* response) const -> netJob->addNetAction(Net::Upload::makeByteArray(QString("https://api.curseforge.com/v1/mods"), response, body_raw)); - QObject::connect(netJob, &NetJob::finished, [response] { delete response; }); + QObject::connect(netJob, &NetJob::finished, [response, netJob] { delete response; netJob->deleteLater(); }); QObject::connect(netJob, &NetJob::failed, [body_raw] { qDebug() << body_raw; }); return netJob; diff --git a/launcher/modplatform/flame/FlameAPI.h b/launcher/modplatform/flame/FlameAPI.h index 1646ec79c..ec6706e57 100644 --- a/launcher/modplatform/flame/FlameAPI.h +++ b/launcher/modplatform/flame/FlameAPI.h @@ -10,7 +10,7 @@ class FlameAPI : public NetworkModAPI { auto getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::IndexedVersion; - auto getProjects(QStringList addonIds, QByteArray* response) const -> NetJob::Ptr override; + auto getProjects(QStringList addonIds, QByteArray* response) const -> NetJob* override; private: inline auto getSortFieldInt(QString sortString) const -> int diff --git a/launcher/modplatform/helpers/NetworkModAPI.cpp b/launcher/modplatform/helpers/NetworkModAPI.cpp index e8cba12e4..90edfe31a 100644 --- a/launcher/modplatform/helpers/NetworkModAPI.cpp +++ b/launcher/modplatform/helpers/NetworkModAPI.cpp @@ -36,7 +36,7 @@ void NetworkModAPI::getModInfo(CallerType* caller, ModPlatform::IndexedPack& pac auto response = new QByteArray(); auto job = getProject(pack.addonId.toString(), response); - QObject::connect(job.get(), &NetJob::succeeded, caller, [caller, &pack, response] { + QObject::connect(job, &NetJob::succeeded, caller, [caller, &pack, response] { QJsonParseError parse_error{}; QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); if (parse_error.error != QJsonParseError::NoError) { @@ -80,7 +80,7 @@ void NetworkModAPI::getVersions(CallerType* caller, VersionSearchArgs&& args) co netJob->start(); } -auto NetworkModAPI::getProject(QString addonId, QByteArray* response) const -> NetJob::Ptr +auto NetworkModAPI::getProject(QString addonId, QByteArray* response) const -> NetJob* { auto netJob = new NetJob(QString("%1::GetProject").arg(addonId), APPLICATION->network()); auto searchUrl = getModInfoURL(addonId); diff --git a/launcher/modplatform/helpers/NetworkModAPI.h b/launcher/modplatform/helpers/NetworkModAPI.h index ea28c688f..989bcec40 100644 --- a/launcher/modplatform/helpers/NetworkModAPI.h +++ b/launcher/modplatform/helpers/NetworkModAPI.h @@ -8,7 +8,7 @@ class NetworkModAPI : public ModAPI { void getModInfo(CallerType* caller, ModPlatform::IndexedPack& pack) override; void getVersions(CallerType* caller, VersionSearchArgs&& args) const override; - auto getProject(QString addonId, QByteArray* response) const -> NetJob::Ptr override; + auto getProject(QString addonId, QByteArray* response) const -> NetJob* override; protected: virtual auto getModSearchURL(SearchArgs& args) const -> QString = 0; diff --git a/launcher/modplatform/modrinth/ModrinthAPI.cpp b/launcher/modplatform/modrinth/ModrinthAPI.cpp index 301c0be89..747cf4c35 100644 --- a/launcher/modplatform/modrinth/ModrinthAPI.cpp +++ b/launcher/modplatform/modrinth/ModrinthAPI.cpp @@ -95,14 +95,14 @@ auto ModrinthAPI::latestVersions(const QStringList& hashes, return netJob; } -auto ModrinthAPI::getProjects(QStringList addonIds, QByteArray* response) const -> NetJob::Ptr +auto ModrinthAPI::getProjects(QStringList addonIds, QByteArray* response) const -> NetJob* { auto netJob = new NetJob(QString("Modrinth::GetProjects"), APPLICATION->network()); auto searchUrl = getMultipleModInfoURL(addonIds); netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), response)); - QObject::connect(netJob, &NetJob::finished, [response] { delete response; }); + QObject::connect(netJob, &NetJob::finished, [response, netJob] { delete response; netJob->deleteLater(); }); return netJob; } diff --git a/launcher/modplatform/modrinth/ModrinthAPI.h b/launcher/modplatform/modrinth/ModrinthAPI.h index 2909daf9c..e1a186813 100644 --- a/launcher/modplatform/modrinth/ModrinthAPI.h +++ b/launcher/modplatform/modrinth/ModrinthAPI.h @@ -47,7 +47,7 @@ class ModrinthAPI : public NetworkModAPI { ModLoaderTypes loaders, QByteArray* response) -> NetJob::Ptr; - auto getProjects(QStringList addonIds, QByteArray* response) const -> NetJob::Ptr override; + auto getProjects(QStringList addonIds, QByteArray* response) const -> NetJob* override; public: inline auto getAuthorURL(const QString& name) const -> QString { return "https://modrinth.com/user/" + name; };