Frontend: Prevent a crash from closing a hosted room using the Disconnect button and then trying to host another room

This commit is contained in:
James Rowe 2018-04-20 00:39:01 -06:00
parent 5fef22fc52
commit c7726f13e8
3 changed files with 6 additions and 5 deletions

View file

@ -13,6 +13,7 @@
#include "citra_qt/game_list_p.h" #include "citra_qt/game_list_p.h"
#include "citra_qt/multiplayer/client_room.h" #include "citra_qt/multiplayer/client_room.h"
#include "citra_qt/multiplayer/message.h" #include "citra_qt/multiplayer/message.h"
#include "citra_qt/multiplayer/state.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/announce_multiplayer_session.h" #include "core/announce_multiplayer_session.h"
#include "ui_client_room.h" #include "ui_client_room.h"
@ -57,11 +58,8 @@ void ClientRoomWindow::OnStateChange(const Network::RoomMember::State& state) {
} }
void ClientRoomWindow::Disconnect() { void ClientRoomWindow::Disconnect() {
if (!NetworkMessage::WarnDisconnect()) { auto parent = static_cast<MultiplayerState*>(parentWidget());
return; if (!parent->OnCloseRoom()) {
}
if (auto member = Network::GetRoomMember().lock()) {
member->Leave();
ui->chat->AppendStatusMessage(tr("Disconnected")); ui->chat->AppendStatusMessage(tr("Disconnected"));
close(); close();
} }

View file

@ -147,6 +147,7 @@ bool MultiplayerState::OnCloseRoom() {
// if you are in a room, leave it // if you are in a room, leave it
if (auto member = Network::GetRoomMember().lock()) { if (auto member = Network::GetRoomMember().lock()) {
member->Leave(); member->Leave();
NGLOG_DEBUG(Frontend, "Left the room (as a client)");
} }
// if you are hosting a room, also stop hosting // if you are hosting a room, also stop hosting
@ -155,6 +156,7 @@ bool MultiplayerState::OnCloseRoom() {
} }
room->Destroy(); room->Destroy();
announce_multiplayer_session->Stop(); announce_multiplayer_session->Stop();
NGLOG_DEBUG(Frontend, "Closed the room (as a server)");
} }
return true; return true;
} }

View file

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <QWidget> #include <QWidget>
#include "core/announce_multiplayer_session.h"
#include "network/network.h" #include "network/network.h"
class QStandardItemModel; class QStandardItemModel;