Merge pull request #183 from timoreo22/fix-versions-segfault

Fixed segfault in mod download
This commit is contained in:
Ezekiel Smith 2022-02-26 01:55:11 +11:00 committed by GitHub
commit f2b850ad20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 9 deletions

View File

@ -113,13 +113,12 @@ void FlameModPage::onSelectionChanged(QModelIndex first, QModelIndex second)
{ {
qDebug() << "Loading flame mod versions"; qDebug() << "Loading flame mod versions";
auto netJob = new NetJob(QString("Flame::ModVersions(%1)").arg(current.name), APPLICATION->network()); auto netJob = new NetJob(QString("Flame::ModVersions(%1)").arg(current.name), APPLICATION->network());
std::shared_ptr<QByteArray> response = std::make_shared<QByteArray>(); auto response = new QByteArray();
int addonId = current.addonId; 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; QJsonParseError parse_error;
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
if(parse_error.error != QJsonParseError::NoError) { if(parse_error.error != QJsonParseError::NoError) {
@ -150,9 +149,13 @@ void FlameModPage::onSelectionChanged(QModelIndex first, QModelIndex second)
if(ui->versionSelectionBox->count() == 0){ if(ui->versionSelectionBox->count() == 0){
ui->versionSelectionBox->addItem(tr("No Valid Version found!"), QVariant(-1)); ui->versionSelectionBox->addItem(tr("No Valid Version found!"), QVariant(-1));
} }
suggestCurrent(); suggestCurrent();
}); });
QObject::connect(netJob, &NetJob::finished, this, [response, netJob]
{
netJob->deleteLater();
delete response;
});
netJob->start(); netJob->start();
} }
else else

View File

@ -98,13 +98,12 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
{ {
qDebug() << "Loading Modrinth mod versions"; qDebug() << "Loading Modrinth mod versions";
auto netJob = new NetJob(QString("Modrinth::ModVersions(%1)").arg(current.name), APPLICATION->network()); auto netJob = new NetJob(QString("Modrinth::ModVersions(%1)").arg(current.name), APPLICATION->network());
std::shared_ptr<QByteArray> response = std::make_shared<QByteArray>(); auto response = new QByteArray();
QString addonId = current.addonId; 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; QJsonParseError parse_error;
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
if(parse_error.error != QJsonParseError::NoError) { if(parse_error.error != QJsonParseError::NoError) {
@ -138,6 +137,10 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
suggestCurrent(); suggestCurrent();
}); });
QObject::connect(netJob, &NetJob::finished, this, [response, netJob]{
netJob->deleteLater();
delete response;
});
netJob->start(); netJob->start();
} }
else else