mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 01:23:24 -08:00
[DlgCreateGame] Heap-allocate create game dialog to prevent crash on parent deletion
This commit is contained in:
parent
df74917cb0
commit
82b74ce594
2 changed files with 14 additions and 7 deletions
|
|
@ -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"));
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue