From 22694fe5e4c7b0ea3c1b06d2b6a9e80dbd1695da Mon Sep 17 00:00:00 2001 From: Volker Krause Date: Thu, 8 Jun 2023 18:18:43 +0200 Subject: [PATCH] Handle invalid model indices gracefully data() being called with an invalid model index seems to happen during normal operations here, with something in the proxy model chain not catching that case (due to a row being filtered out presumably?). --- src/models/messageeventmodel.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/models/messageeventmodel.cpp b/src/models/messageeventmodel.cpp index 6b17385ed..c21b6528d 100644 --- a/src/models/messageeventmodel.cpp +++ b/src/models/messageeventmodel.cpp @@ -434,7 +434,9 @@ static LinkPreviewer *emptyLinkPreview = new LinkPreviewer; QVariant MessageEventModel::data(const QModelIndex &idx, int role) const { - Q_ASSERT(checkIndex(idx, QAbstractItemModel::CheckIndexOption::IndexIsValid)); + if (!checkIndex(idx, QAbstractItemModel::CheckIndexOption::IndexIsValid)) { + return {}; + } const auto row = idx.row(); if (!m_currentRoom || row < 0 || row >= int(m_currentRoom->pendingEvents().size()) + m_currentRoom->timelineSize()) {