Add defensive checks on index and iterators

This commit is contained in:
Ashley Coleman 2020-11-16 17:51:09 -08:00 committed by huderlem
parent f50743b3d0
commit 8567d161b5
2 changed files with 16 additions and 2 deletions

5
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,5 @@
{
"files.associations": {
"map": "cpp"
}
}

View file

@ -374,13 +374,22 @@ void Editor::deleteWildMonGroup() {
if (msgBox.clickedButton() == deleteButton) {
auto it = project->wildMonData.find(map->constantName);
it.value().erase(labelCombo->currentText());
if (it == project->wildMonData.end()) {
logError(QString("Failed to find data for map %s. Unable to delete").arg(map->constantName));
return;
}
int i = project->encounterGroupLabels.indexOf(labelCombo->currentText());
if (i < 0) {
logError(QString("Failed to find selected wild mon group: %s. Unable to delete")
.arg(labelCombo->currentText()));
return;
}
it.value().erase(labelCombo->currentText());
project->encounterGroupLabels.remove(i);
displayWildMonTables();
emit wildMonDataChanged();
}
}