mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
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.
This commit is contained in:
@ -21,7 +21,11 @@
|
||||
static QString GetPlayerNameFromPID(int pid)
|
||||
{
|
||||
QString player_name = QObject::tr("Invalid Player ID");
|
||||
for (const auto* player : Settings::Instance().GetNetPlayClient()->GetPlayers())
|
||||
auto client = Settings::Instance().GetNetPlayClient();
|
||||
if (!client)
|
||||
return player_name;
|
||||
|
||||
for (const auto* player : client->GetPlayers())
|
||||
{
|
||||
if (player->pid == pid)
|
||||
{
|
||||
@ -82,7 +86,11 @@ void MD5Dialog::show(const QString& title)
|
||||
m_results.clear();
|
||||
m_check_label->setText(QString::fromStdString(""));
|
||||
|
||||
for (const auto* player : Settings::Instance().GetNetPlayClient()->GetPlayers())
|
||||
auto client = Settings::Instance().GetNetPlayClient();
|
||||
if (!client)
|
||||
return;
|
||||
|
||||
for (const auto* player : client->GetPlayers())
|
||||
{
|
||||
m_progress_bars[player->pid] = new QProgressBar;
|
||||
m_status_labels[player->pid] = new QLabel;
|
||||
@ -118,7 +126,8 @@ void MD5Dialog::SetResult(int pid, const std::string& result)
|
||||
|
||||
m_results.push_back(result);
|
||||
|
||||
if (m_results.size() >= Settings::Instance().GetNetPlayClient()->GetPlayers().size())
|
||||
auto client = Settings::Instance().GetNetPlayClient();
|
||||
if (client && m_results.size() >= client->GetPlayers().size())
|
||||
{
|
||||
if (std::adjacent_find(m_results.begin(), m_results.end(), std::not_equal_to<>()) ==
|
||||
m_results.end())
|
||||
@ -134,7 +143,7 @@ void MD5Dialog::SetResult(int pid, const std::string& result)
|
||||
|
||||
void MD5Dialog::reject()
|
||||
{
|
||||
auto* server = Settings::Instance().GetNetPlayServer();
|
||||
auto server = Settings::Instance().GetNetPlayServer();
|
||||
|
||||
if (server)
|
||||
server->AbortMD5();
|
||||
|
@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,8 @@ void PadMappingDialog::ConnectWidgets()
|
||||
|
||||
int PadMappingDialog::exec()
|
||||
{
|
||||
auto* client = Settings::Instance().GetNetPlayClient();
|
||||
auto* server = Settings::Instance().GetNetPlayServer();
|
||||
auto client = Settings::Instance().GetNetPlayClient();
|
||||
auto server = Settings::Instance().GetNetPlayServer();
|
||||
// Load Settings
|
||||
m_players = client->GetPlayers();
|
||||
m_pad_mapping = server->GetPadMapping();
|
||||
|
Reference in New Issue
Block a user