aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThierry Crozat2017-11-24 22:21:44 +0000
committerThierry Crozat2017-11-24 22:44:41 +0000
commit469e75cb64c4acd2914ec845915637e9144b159a (patch)
tree53672bab789c2259590d107a4c37b88613419b0a
parent150f70f94c3d8cf762ca564ac6c05fa52c62f9a8 (diff)
downloadscummvm-rg350-469e75cb64c4acd2914ec845915637e9144b159a.tar.gz
scummvm-rg350-469e75cb64c4acd2914ec845915637e9144b159a.tar.bz2
scummvm-rg350-469e75cb64c4acd2914ec845915637e9144b159a.zip
GUI: Fix incorrect SaveLoad dialog state after updating the save list
Updating the list reset the selection in the list widget, however if a save had previously been selected and the Choose button was enabled, it remained enabled despite no save being selected. Trying to load the game resulted in a crash. This was particularly an issue with cloud enabled as if you are unlucky you could have tried to load a save just as the cloud sync finished, which updated the list and unselected the save. This change fixes bug #9766: Assert in SaveLoadChooser dialog. In addition to adding a sanity check on the selected index for the Choose command, this commit also preserves the selection when updating the list as I think this would be the expected behaviour in this dialog.
-rw-r--r--gui/saveload-dialog.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp
index 4bf23b8974..cbfaaed8dd 100644
--- a/gui/saveload-dialog.cpp
+++ b/gui/saveload-dialog.cpp
@@ -428,11 +428,13 @@ void SaveLoadChooserSimple::handleCommand(CommandSender *sender, uint32 cmd, uin
break;
case kChooseCmd:
_list->endEditMode();
- if (!_saveList.empty()) {
- setResult(_saveList[selItem].getSaveSlot());
- _resultString = _list->getSelectedString();
+ if (selItem >= 0) {
+ if (!_saveList.empty()) {
+ setResult(_saveList[selItem].getSaveSlot());
+ _resultString = _list->getSelectedString();
+ }
+ close();
}
- close();
break;
case kListSelectionChangedCmd:
updateSelection(true);
@@ -694,7 +696,13 @@ void SaveLoadChooserSimple::updateSaveList() {
colors.push_back(ThemeEngine::kFontColorNormal);
}
+ int selected = _list->getSelected();
_list->setList(saveNames, &colors);
+ if (selected >= 0 && selected < saveNames.size())
+ _list->setSelected(selected);
+ else
+ _chooseButton->setEnabled(false);
+
draw();
}