From 6edc458e83c2daf446fb81a1fa3e5a3bfb06e533 Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Tue, 27 Jan 2015 06:50:42 +0200 Subject: Fix crash when no dives were selected for downloading Signed-off-by: Miika Turkia Signed-off-by: Dirk Hohndel --- qt-ui/downloadfromdivecomputer.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'qt-ui/downloadfromdivecomputer.cpp') diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp index 6fa83e118..cd3dd90d0 100644 --- a/qt-ui/downloadfromdivecomputer.cpp +++ b/qt-ui/downloadfromdivecomputer.cpp @@ -418,6 +418,8 @@ void DownloadFromDCWidget::on_cancel_clicked() void DownloadFromDCWidget::on_ok_clicked() { + struct dive *dive; + if (currentState != DONE) return; @@ -433,16 +435,20 @@ void DownloadFromDCWidget::on_ok_clicked() // remember the last downloaded dive (on most dive computers this will be the chronologically // first new dive) and select it again after processing all the dives MainWindow::instance()->dive_list()->unselectDives(); - uniqId = get_dive(dive_table.nr - 1)->id; - process_dives(true, preferDownloaded()); - // after process_dives does any merging or resorting needed, we need - // to recreate the model for the dive list so we can select the newest dive - MainWindow::instance()->recreateDiveList(); - idx = get_idx_by_uniq_id(uniqId); - // this shouldn't be necessary - but there are reports that somehow existing dives stay selected - // (but not visible as selected) - MainWindow::instance()->dive_list()->unselectDives(); - MainWindow::instance()->dive_list()->selectDive(idx, true); + + dive = get_dive(dive_table.nr - 1); + if (dive != NULL) { + uniqId = get_dive(dive_table.nr - 1)->id; + process_dives(true, preferDownloaded()); + // after process_dives does any merging or resorting needed, we need + // to recreate the model for the dive list so we can select the newest dive + MainWindow::instance()->recreateDiveList(); + idx = get_idx_by_uniq_id(uniqId); + // this shouldn't be necessary - but there are reports that somehow existing dives stay selected + // (but not visible as selected) + MainWindow::instance()->dive_list()->unselectDives(); + MainWindow::instance()->dive_list()->selectDive(idx, true); + } if (ostcFirmwareCheck && currentState == DONE) ostcFirmwareCheck->checkLatest(this, &data); -- cgit v1.2.3-70-g09d2