fix segfault on disconnect (#5447)

* add new param to closeRequest

* don't emit signals in dtors

* send closeRequest

* fix build failure

* fix build failure

* see if we can get away with the overloaded triggered

* fix build failure
This commit is contained in:
RickyRister 2025-01-11 19:19:45 -08:00 committed by GitHub
parent 3b544a36a8
commit 7347ba88ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 59 additions and 67 deletions

View file

@ -581,16 +581,14 @@ void TabGame::emitUserEvent()
TabGame::~TabGame()
{
scene->clearViews();
delete replay;
QMapIterator<int, Player *> i(players);
while (i.hasNext()) {
delete i.next().value();
}
players.clear();
emit gameClosing(this);
}
void TabGame::updatePlayerListDockTitle()
@ -701,9 +699,15 @@ void TabGame::retranslateUi()
scene->retranslateUi();
}
void TabGame::closeRequest()
void TabGame::closeRequest(bool forced)
{
actLeaveGame();
if (!forced && !leaveGame()) {
return;
}
emit gameClosing(this);
deleteLater();
}
void TabGame::replayNextEvent(Player::EventProcessingOptions options)
@ -794,19 +798,23 @@ void TabGame::actConcede()
}
}
void TabGame::actLeaveGame()
/**
* Confirms the leave game and sends the leave game command, if applicable.
*
* @return True if the leave game is confirmed
*/
bool TabGame::leaveGame()
{
if (!gameClosed) {
if (!spectator)
if (QMessageBox::question(this, tr("Leave game"), tr("Are you sure you want to leave this game?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
return;
return false;
if (!replay)
sendGameCommand(Command_LeaveGame());
}
scene->clearViews();
deleteLater();
return true;
}
void TabGame::actSay()
@ -1598,7 +1606,7 @@ void TabGame::createMenuItems()
aConcede = new QAction(this);
connect(aConcede, SIGNAL(triggered()), this, SLOT(actConcede()));
aLeaveGame = new QAction(this);
connect(aLeaveGame, SIGNAL(triggered()), this, SLOT(actLeaveGame()));
connect(aLeaveGame, &QAction::triggered, this, [this] { closeRequest(); });
aFocusChat = new QAction(this);
connect(aFocusChat, SIGNAL(triggered()), sayEdit, SLOT(setFocus()));
aCloseReplay = nullptr;
@ -1648,7 +1656,7 @@ void TabGame::createReplayMenuItems()
aFocusChat = nullptr;
aLeaveGame = nullptr;
aCloseReplay = new QAction(this);
connect(aCloseReplay, SIGNAL(triggered()), this, SLOT(actLeaveGame()));
connect(aCloseReplay, &QAction::triggered, this, [this] { closeRequest(); });
phasesMenu = nullptr;
gameMenu = new QMenu(this);