From adacab33494f307a93e41ac0eee4fdd226c39614 Mon Sep 17 00:00:00 2001 From: timoreo Date: Sat, 19 Feb 2022 15:17:45 +0100 Subject: [PATCH] Fixed segfault when closing window while version info download is still going --- .../ui/pages/modplatform/flame/FlameModPage.cpp | 13 ++++++++----- .../ui/pages/modplatform/modrinth/ModrinthPage.cpp | 11 +++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp index a816c681..4afdd142 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp @@ -113,13 +113,12 @@ void FlameModPage::onSelectionChanged(QModelIndex first, QModelIndex second) { qDebug() << "Loading flame mod versions"; auto netJob = new NetJob(QString("Flame::ModVersions(%1)").arg(current.name), APPLICATION->network()); - std::shared_ptr response = std::make_shared(); + auto response = new QByteArray(); int addonId = current.addonId; - netJob->addNetAction(Net::Download::makeByteArray(QString("https://addons-ecs.forgesvc.net/api/v2/addon/%1/files").arg(addonId), response.get())); + netJob->addNetAction(Net::Download::makeByteArray(QString("https://addons-ecs.forgesvc.net/api/v2/addon/%1/files").arg(addonId), response)); - QObject::connect(netJob, &NetJob::succeeded, this, [this, response, netJob] + QObject::connect(netJob, &NetJob::succeeded, this, [this, response] { - netJob->deleteLater(); QJsonParseError parse_error; QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); if(parse_error.error != QJsonParseError::NoError) { @@ -150,9 +149,13 @@ void FlameModPage::onSelectionChanged(QModelIndex first, QModelIndex second) if(ui->versionSelectionBox->count() == 0){ ui->versionSelectionBox->addItem(tr("No Valid Version found!"), QVariant(-1)); } - suggestCurrent(); }); + QObject::connect(netJob, &NetJob::finished, this, [response, netJob] + { + netJob->deleteLater(); + delete response; + }); netJob->start(); } else diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp index c5a54c29..577a7bcb 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp @@ -98,13 +98,12 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) { qDebug() << "Loading Modrinth mod versions"; auto netJob = new NetJob(QString("Modrinth::ModVersions(%1)").arg(current.name), APPLICATION->network()); - std::shared_ptr response = std::make_shared(); + auto response = new QByteArray(); QString addonId = current.addonId; - netJob->addNetAction(Net::Download::makeByteArray(QString("https://api.modrinth.com/v2/project/%1/version").arg(addonId), response.get())); + netJob->addNetAction(Net::Download::makeByteArray(QString("https://api.modrinth.com/v2/project/%1/version").arg(addonId), response)); - QObject::connect(netJob, &NetJob::succeeded, this, [this, response, netJob] + QObject::connect(netJob, &NetJob::succeeded, this, [this, response] { - netJob->deleteLater(); QJsonParseError parse_error; QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); if(parse_error.error != QJsonParseError::NoError) { @@ -138,6 +137,10 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) suggestCurrent(); }); + QObject::connect(netJob, &NetJob::finished, this, [response, netJob]{ + netJob->deleteLater(); + delete response; + }); netJob->start(); } else