CylindersModel: don't crash if accessing non-existing cylinder

It shouldn't happen, but currently we overwrite the displayed_dive
without updating the CylindersModel. Thus, CylindersModel may now
crash when the new displayed_dive has less cylinders than the old
one.

For now, catch this condition. Treat the root cause later.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-01-30 14:33:27 +01:00 committed by Dirk Hohndel
parent 906cce9e88
commit 62b869b24a

View file

@ -134,6 +134,11 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
if (!index.isValid() || index.row() >= rows)
return QVariant();
if (index.row() >= displayed_dive.cylinders.nr) {
qWarning("CylindersModel and displayed_dive are out of sync!");
return QVariant();
}
const cylinder_t *cyl = get_cylinder(&displayed_dive, index.row());
switch (role) {