Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes some crashes regarding high network usage #1145

Merged
merged 2 commits into from Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions launcher/net/ByteArraySink.h
Expand Up @@ -53,23 +53,32 @@ class ByteArraySink : public Sink {
public:
auto init(QNetworkRequest& request) -> Task::State override
{
m_output->clear();
if (m_output)
m_output->clear();
else
qWarning() << "ByteArraySink did not initialize the buffer because it's not addressable";
if (initAllValidators(request))
return Task::State::Running;
return Task::State::Failed;
};

auto write(QByteArray& data) -> Task::State override
{
m_output->append(data);
if (m_output)
m_output->append(data);
else
qWarning() << "ByteArraySink did not write the buffer because it's not addressable";
if (writeAllValidators(data))
return Task::State::Running;
return Task::State::Failed;
}

auto abort() -> Task::State override
{
m_output->clear();
if (m_output)
m_output->clear();
else
qWarning() << "ByteArraySink did not clear the buffer because it's not addressable";
failAllValidators();
return Task::State::Failed;
}
Expand Down
3 changes: 1 addition & 2 deletions launcher/tasks/ConcurrentTask.cpp
Expand Up @@ -138,19 +138,18 @@ void ConcurrentTask::startNext()
connect(next.get(), &Task::progress, this, [this, next](qint64 current, qint64 total) { subTaskProgress(next, current, total); });

m_doing.insert(next.get(), next);
qsizetype num_starts = qMin(m_queue.size(), m_total_max_size - m_doing.size());
auto task_progress = std::make_shared<TaskStepProgress>(next->getUid());
m_task_progress.insert(next->getUid(), task_progress);

updateState();
updateStepProgress(*task_progress.get(), Operation::ADDED);


QCoreApplication::processEvents();

QMetaObject::invokeMethod(next.get(), &Task::start, Qt::QueuedConnection);

// Allow going up the number of concurrent tasks in case of tasks being added in the middle of a running task.
int num_starts = qMin(m_queue.size(), m_total_max_size - m_doing.size());
for (int i = 0; i < num_starts; i++)
QMetaObject::invokeMethod(this, &ConcurrentTask::startNext, Qt::QueuedConnection);
}
Expand Down
9 changes: 6 additions & 3 deletions launcher/ui/pages/modplatform/ResourcePage.cpp
Expand Up @@ -240,10 +240,13 @@ void ResourcePage::updateSelectionButton()
}

m_ui->resourceSelectionButton->setEnabled(true);
if (!getCurrentPack()->isVersionSelected(m_selected_version_index)) {
m_ui->resourceSelectionButton->setText(tr("Select %1 for download").arg(resourceString()));
if (getCurrentPack()) {
if (!getCurrentPack()->isVersionSelected(m_selected_version_index))
m_ui->resourceSelectionButton->setText(tr("Select %1 for download").arg(resourceString()));
else
m_ui->resourceSelectionButton->setText(tr("Deselect %1 for download").arg(resourceString()));
} else {
m_ui->resourceSelectionButton->setText(tr("Deselect %1 for download").arg(resourceString()));
qWarning() << "Tried to update the selected button but there is not a pack selected";
}
}

Expand Down