[DlgCreateGame] Heap-allocate create game dialog to prevent crash on parent deletion

This commit is contained in:
sentry[bot] 2026-11-05 06:07:38 +00:00 • committed by GitHub
parent df74917cb0
commit 82b74ce594
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 7 deletions

View file

@ -266,9 +266,13 @@ void GameSelector::actCreate()
return;
}
DlgCreateGame dlg(room, room->getGameTypes(), this);
dlg.exec();
updateTitle();
// Heap-allocate the dialog: if this selector (or its room tab) is destroyed while the
// dialog is open, e.g. on server disconnect, Qt deletes its children. A stack-allocated
// child would then be deleted by Qt and crash.
auto *dlg = new DlgCreateGame(room, room->getGameTypes(), this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
connect(dlg, &QDialog::finished, this, &GameSelector::updateTitle);
dlg->open();
}
void GameSelector::checkResponse(const Response &response)
@ -362,8 +366,9 @@ void GameSelector::customContextMenu(const QPoint &point)
const ServerInfo_Game &gameInfo = gameListModel->getGame(index.data(Qt::UserRole).toInt());
const QMap<int, QString> &gameTypes = gameListModel->getGameTypes().value(gameInfo.room_id());
DlgCreateGame dlg(gameInfo, gameTypes, this);
dlg.exec();
auto *dlg = new DlgCreateGame(gameInfo, gameTypes, this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->open();
});
QAction copyLink(tr("Cop&y game link"));

View file

@ -570,8 +570,10 @@ void TabGame::adminLockChanged(bool lock)
void TabGame::actGameInfo()
{
DlgCreateGame dlg(game->getGameMetaInfo()->proto(), game->getGameMetaInfo()->getRoomGameTypes(), this);
dlg.exec();
// Heap-allocated so that destroying this tab while the dialog is open cannot delete a stack object.
auto *dlg = new DlgCreateGame(game->getGameMetaInfo()->proto(), game->getGameMetaInfo()->getRoomGameTypes(), this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->open();
}
void TabGame::actCopyGameLink()