[PATCH 1/3] Planner: fix potential assert in clear()

Lubomir I. Ivanov neolit123 at gmail.com
Mon Dec 9 15:02:06 UTC 2013


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

If rowCount() is 0 we get an assert:
ASSERT: "last >= first" in file kernel/qabstractitemmodel.cpp...

To solve that we wrap the beginRemoveRows() call in a bnrach:
if (rowCount() > 0) {
...

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---

not sure if this is the correct way to do this.
---
 qt-ui/diveplanner.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index c5ca7f7..dedbd61 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -1396,9 +1396,11 @@ void DivePlannerPointsModel::clear()
 		memset(stagingDive->cylinder, 0, MAX_CYLINDERS * sizeof(cylinder_t));
 	}
 	CylindersModel::instance()->setDive(stagingDive);
-	beginRemoveRows(QModelIndex(), 0, rowCount()-1);
-	divepoints.clear();
-	endRemoveRows();
+	if (rowCount() > 0) {
+		beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
+		divepoints.clear();
+		endRemoveRows();
+	}
 	CylindersModel::instance()->clear();
 }
 
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list