From 42dd5dfc58504eeab1d026a97f61cc1afd35fced Mon Sep 17 00:00:00 2001 From: APTX Date: Sun, 26 Nov 2017 20:02:23 +0900 Subject: [PATCH] Make sure model indexes are valid --- core/annotationmodel.cpp | 2 ++ core/chaptermodel.cpp | 3 +++ core/trackmodel.cpp | 3 +++ 3 files changed, 8 insertions(+) diff --git a/core/annotationmodel.cpp b/core/annotationmodel.cpp index 1fd3682..edeaf74 100644 --- a/core/annotationmodel.cpp +++ b/core/annotationmodel.cpp @@ -29,6 +29,8 @@ int AnnotationModel::rowCount(const QModelIndex &parent) const { } QVariant AnnotationModel::data(const QModelIndex &index, int role) const { + if (!index.isValid()) + return {}; const PlayerFeaturePlauginInterface::Annotation &annotation = m_data.at(index.row()); diff --git a/core/chaptermodel.cpp b/core/chaptermodel.cpp index 15b0942..02dd790 100644 --- a/core/chaptermodel.cpp +++ b/core/chaptermodel.cpp @@ -30,6 +30,9 @@ int ChapterModel::rowCount(const QModelIndex &parent) const { } QVariant ChapterModel::data(const QModelIndex &index, int role) const { + if (!index.isValid()) + return {}; + switch (role) { case TitleRole: case Qt::DisplayRole: diff --git a/core/trackmodel.cpp b/core/trackmodel.cpp index 2ba46eb..76a82fe 100644 --- a/core/trackmodel.cpp +++ b/core/trackmodel.cpp @@ -27,6 +27,9 @@ int TrackModel::rowCount(const QModelIndex &parent) const { QVariant TrackModel::data(const QModelIndex &index, int role) const { static PlayerPluginInterface::Track noneTrackData{"None", "", -1}; + if (!index.isValid()) + return {}; + auto &trackData = (index.row() == 0) ? noneTrackData : m_data[index.row() - 1]; -- 2.52.0