From: APTX Date: Sun, 26 Nov 2017 11:02:23 +0000 (+0900) Subject: Make sure model indexes are valid X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=42dd5dfc58504eeab1d026a97f61cc1afd35fced;p=aniplayer.git Make sure model indexes are valid --- 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];