Skip to content

Commit

Permalink
Merge pull request #9028 from cristian64/netplaybrowser_deadlock_on_exit
Browse files Browse the repository at this point in the history
DolphinQt: Prevent deadlock when exiting the NetPlay Session Browser dialog
  • Loading branch information
lioncash committed Aug 16, 2020
2 parents 6fc7135 + ddeb223 commit 2c5920d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
38 changes: 21 additions & 17 deletions Source/Core/DolphinQt/NetPlay/NetPlayBrowser.cpp
Expand Up @@ -26,7 +26,6 @@
#include "Core/ConfigManager.h"

#include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/QtUtils/RunOnObject.h"
#include "DolphinQt/Settings.h"

NetPlayBrowser::NetPlayBrowser(QWidget* parent) : QDialog(parent)
Expand All @@ -35,6 +34,7 @@ NetPlayBrowser::NetPlayBrowser(QWidget* parent) : QDialog(parent)
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

CreateWidgets();
RestoreSettings();
ConnectWidgets();

resize(750, 500);
Expand All @@ -45,8 +45,6 @@ NetPlayBrowser::NetPlayBrowser(QWidget* parent) : QDialog(parent)
m_refresh_run.Set(true);
m_refresh_thread = std::thread([this] { RefreshLoop(); });

RestoreSettings();

UpdateList();
Refresh();
}
Expand Down Expand Up @@ -149,6 +147,11 @@ void NetPlayBrowser::ConnectWidgets()
connect(m_table_widget, &QTableWidget::itemSelectionChanged, this,
&NetPlayBrowser::OnSelectionChanged);
connect(m_table_widget, &QTableWidget::itemDoubleClicked, this, &NetPlayBrowser::accept);

connect(this, &NetPlayBrowser::UpdateStatusRequested, this,
&NetPlayBrowser::OnUpdateStatusRequested, Qt::QueuedConnection);
connect(this, &NetPlayBrowser::UpdateListRequested, this, &NetPlayBrowser::OnUpdateListRequested,
Qt::QueuedConnection);
}

void NetPlayBrowser::Refresh()
Expand Down Expand Up @@ -192,30 +195,20 @@ void NetPlayBrowser::RefreshLoop()

lock.unlock();

RunOnObject(this, [this] {
m_status_label->setText(tr("Refreshing..."));
return nullptr;
});
emit UpdateStatusRequested(tr("Refreshing..."));

NetPlayIndex client;

auto entries = client.List(filters);

if (entries)
{
RunOnObject(this, [this, &entries] {
m_sessions = *entries;
UpdateList();
return nullptr;
});
emit UpdateListRequested(std::move(*entries));
}
else
{
RunOnObject(this, [this, &client] {
m_status_label->setText(tr("Error obtaining session list: %1")
.arg(QString::fromStdString(client.GetLastError())));
return nullptr;
});
emit UpdateStatusRequested(tr("Error obtaining session list: %1")
.arg(QString::fromStdString(client.GetLastError())));
}
}
}
Expand Down Expand Up @@ -278,6 +271,17 @@ void NetPlayBrowser::OnSelectionChanged()
->setEnabled(!m_table_widget->selectedItems().isEmpty());
}

void NetPlayBrowser::OnUpdateStatusRequested(const QString& status)
{
m_status_label->setText(status);
}

void NetPlayBrowser::OnUpdateListRequested(std::vector<NetPlaySession> sessions)
{
m_sessions = std::move(sessions);
UpdateList();
}

void NetPlayBrowser::accept()
{
if (m_table_widget->selectedItems().isEmpty())
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/DolphinQt/NetPlay/NetPlayBrowser.h
Expand Up @@ -35,6 +35,8 @@ class NetPlayBrowser : public QDialog
void accept() override;
signals:
void Join();
void UpdateStatusRequested(const QString& status);
void UpdateListRequested(std::vector<NetPlaySession> sessions);

private:
void CreateWidgets();
Expand All @@ -46,6 +48,9 @@ class NetPlayBrowser : public QDialog

void OnSelectionChanged();

void OnUpdateStatusRequested(const QString& status);
void OnUpdateListRequested(std::vector<NetPlaySession> sessions);

void SaveSettings() const;
void RestoreSettings();

Expand All @@ -71,3 +76,5 @@ class NetPlayBrowser : public QDialog
Common::Flag m_refresh_run;
Common::Event m_refresh_event;
};

Q_DECLARE_METATYPE(std::vector<NetPlaySession>)

0 comments on commit 2c5920d

Please sign in to comment.