mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DlgCreateGame dlg(room, room->getGameTypes(), this);
|
// Heap-allocate the dialog: if this selector (or its room tab) is destroyed while the
|
||||||
dlg.exec();
|
// dialog is open, e.g. on server disconnect, Qt deletes its children. A stack-allocated
|
||||||
updateTitle();
|
// 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)
|
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 ServerInfo_Game &gameInfo = gameListModel->getGame(index.data(Qt::UserRole).toInt());
|
||||||
const QMap<int, QString> &gameTypes = gameListModel->getGameTypes().value(gameInfo.room_id());
|
const QMap<int, QString> &gameTypes = gameListModel->getGameTypes().value(gameInfo.room_id());
|
||||||
|
|
||||||
DlgCreateGame dlg(gameInfo, gameTypes, this);
|
auto *dlg = new DlgCreateGame(gameInfo, gameTypes, this);
|
||||||
dlg.exec();
|
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
dlg->open();
|
||||||
});
|
});
|
||||||
|
|
||||||
QAction copyLink(tr("Cop&y game link"));
|
QAction copyLink(tr("Cop&y game link"));
|
||||||
|
|
|
||||||
|
|
@ -570,8 +570,10 @@ void TabGame::adminLockChanged(bool lock)
|
||||||
|
|
||||||
void TabGame::actGameInfo()
|
void TabGame::actGameInfo()
|
||||||
{
|
{
|
||||||
DlgCreateGame dlg(game->getGameMetaInfo()->proto(), game->getGameMetaInfo()->getRoomGameTypes(), this);
|
// Heap-allocated so that destroying this tab while the dialog is open cannot delete a stack object.
|
||||||
dlg.exec();
|
auto *dlg = new DlgCreateGame(game->getGameMetaInfo()->proto(), game->getGameMetaInfo()->getRoomGameTypes(), this);
|
||||||
|
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
dlg->open();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGame::actCopyGameLink()
|
void TabGame::actCopyGameLink()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue