Commit 817ad710 authored by Johan Ouwerkerk's avatar Johan Ouwerkerk

Fix segfault when attempting to generate or enter in an invalid game variant.

Summary:
This change resolves T5981.
The segfault is fixed by checking whether or not a Game object is valid, before letting the user play with it.

Test Plan:
Manually added a borked game variant in KSudoku::updateShapesList() using a CustomGameVariant with null QUrl.
Compiled and verified the segfault no longer occurred.

```
/*
 * For the purpose of testing the change, a deliberately borked game variant.
 * TODO: remove in final version of diff.
 */
variant = new CustomGame(i18n("Invalid TODO Remove me"), QUrl(), m_gameVariants);
variant->setDescription(i18n("Invalid TODO Remove me"));
variant->setIcon("ksudoku-ksudoku_9x9");
```

Reviewers: #kde_games, ltoscano

Reviewed By: ltoscano

Subscribers: ltoscano, #kde_games

Maniphest Tasks: T5981

Differential Revision: https://phabricator.kde.org/D5671
parent 52bdce6a
......@@ -143,10 +143,16 @@ void WelcomeScreen::configureVariant() {
void WelcomeScreen::startEmptyGame() {
GameVariant* variant = selectedVariant();
if(!variant) return;
if(!variant) {
KMessageBox::sorry(this, i18n("Please select a puzzle variant."), i18n("Unable to start puzzle"));
return;
}
Game game = variant->startEmpty();
if (! game.isValid()) return;
if (! game.isValid()) {
KMessageBox::sorry(this, i18n("Unable to create an empty puzzle of the chosen variant; please try another."), i18n("Unable to start puzzle"));
return;
}
emit newGameStarted(game, variant);
}
......@@ -154,18 +160,32 @@ void WelcomeScreen::startEmptyGame() {
void WelcomeScreen::playVariant() {
return; // Disable old game-creation code.
GameVariant* variant = selectedVariant();
if(!variant) return;
if(!variant) {
KMessageBox::sorry(this, i18n("Please select a puzzle variant."), i18n("Unable to start puzzle"));
return;
}
Game game = variant->createGame(difficulty(), 0);
if(!game.isValid()) {
KMessageBox::sorry(this, i18n("Unable to start a puzzle of the chosen variant; please try another."), i18n("Unable to start puzzle"));
return;
}
emit newGameStarted(game, variant);
}
void WelcomeScreen::generatePuzzle() {
GameVariant* variant = selectedVariant();
if(!variant) return;
if(!variant) {
KMessageBox::sorry(this, i18n("Please select a puzzle variant."), i18n("Unable to start puzzle"));
return;
}
Game game = variant->createGame(difficulty(), symmetry());
if(!game.isValid()) {
KMessageBox::sorry(this, i18n("Unable to generate a puzzle of the chosen variant; please try another."), i18n("Unable to start puzzle"));
return;
}
// Save the selected puzzle configuration.
QModelIndex index = gameListWidget->currentIndex();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment