From 25e432e1d16efaaf0db3112222e7e3716c8e6304 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 13 Nov 2013 13:59:02 +0900 Subject: When selection gets confused, don't try to select non-existing dive While the argument could be made that this is just a symptom of Subsurface getting very confused about the selection (which it still gets at times - most likely we are calling select_dive() instead of selectDive() (or the corresponding deselect functions) in places where we shouldn't), but either way, we should not crash. Fixes #220 Signed-off-by: Dirk Hohndel --- qt-ui/divelistview.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 0fdd6fc91..f33d709e9 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -119,6 +119,8 @@ void DiveListView::unselectDives() void DiveListView::selectDive(struct dive *dive, bool scrollto, bool toggle) { + if (dive == NULL) + return; QSortFilterProxyModel *m = qobject_cast(model()); QModelIndexList match = m->match(m->index(0,0), DiveTripModel::NR, dive->number, 1, Qt::MatchRecursive); QItemSelectionModel::SelectionFlags flags; @@ -227,7 +229,7 @@ void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort) return; sortByColumn(sortColumn, currentOrder); - if (amount_selected && selected_dive >= 0) { + if (amount_selected && current_dive != NULL) { selectDive(current_dive, true); } else { QModelIndex firstDiveOrTrip = m->index(0,0); -- cgit v1.2.3-70-g09d2