summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
diff options
context:
space:
mode:
authorTechjar <tecknojar@gmail.com>2018-07-12 20:37:12 -0400
committerTechjar <tecknojar@gmail.com>2018-07-21 00:04:14 -0400
commitcfeffdcf4208686d64d509f559272d64bbd5da70 (patch)
tree661c18a10d3ca134441d4082ddde1231a74cf7ad /Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
parenta21d536f99ae75f6f8f23870043ed1c8ab19c34d (diff)
Fix more segfaults on NetPlay quit
Basically everything here was race conditions in Qt callbacks, so I changed the client/server instances to std::shared_ptr and added null checks. It checks that the object exists in the callback, and the shared_ptr ensures it doesn't get destroyed until we're done with it. MD5 check would also cause a segfault if you quit without cancelling it first, which was pretty silly.
Diffstat (limited to 'Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp')
-rw-r--r--Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
index ce296acef8..5e3d757eeb 100644
--- a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
+++ b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
@@ -240,8 +240,9 @@ void NetPlayDialog::ConnectWidgets()
if (value == m_buffer_size)
return;
- if (Settings::Instance().GetNetPlayServer() != nullptr)
- Settings::Instance().GetNetPlayServer()->AdjustPadBufferSize(value);
+ auto server = Settings::Instance().GetNetPlayServer();
+ if (server)
+ server->AdjustPadBufferSize(value);
});
connect(m_start_button, &QPushButton::clicked, this, &NetPlayDialog::OnStart);
@@ -371,7 +372,10 @@ void NetPlayDialog::show(std::string nickname, bool use_traversal)
void NetPlayDialog::UpdateGUI()
{
- auto* client = Settings::Instance().GetNetPlayClient();
+ auto client = Settings::Instance().GetNetPlayClient();
+ auto server = Settings::Instance().GetNetPlayServer();
+ if (!client)
+ return;
// Update Player List
const auto players = client->GetPlayers();
@@ -466,11 +470,10 @@ void NetPlayDialog::UpdateGUI()
break;
}
}
- else if (Settings::Instance().GetNetPlayServer())
+ else if (server)
{
- m_hostcode_label->setText(
- QString::fromStdString(Settings::Instance().GetNetPlayServer()->GetInterfaceHost(
- m_room_box->currentData().toString().toStdString())));
+ m_hostcode_label->setText(QString::fromStdString(
+ server->GetInterfaceHost(m_room_box->currentData().toString().toStdString())));
m_hostcode_action_button->setText(tr("Copy"));
m_hostcode_action_button->setEnabled(true);
}
@@ -555,7 +558,7 @@ void NetPlayDialog::GameStatusChanged(bool running)
void NetPlayDialog::SetOptionsEnabled(bool enabled)
{
- if (Settings::Instance().GetNetPlayServer() != nullptr)
+ if (Settings::Instance().GetNetPlayServer())
{
m_start_button->setEnabled(enabled);
m_game_button->setEnabled(enabled);
@@ -574,7 +577,9 @@ void NetPlayDialog::OnMsgStartGame()
DisplayMessage(tr("Started game"), "green");
QueueOnObject(this, [this] {
- Settings::Instance().GetNetPlayClient()->StartGame(FindGame(m_current_game));
+ auto client = Settings::Instance().GetNetPlayClient();
+ if (client)
+ client->StartGame(FindGame(m_current_game));
});
}