From 7e7d271b3062dbf0c06fc77d1697a673d8e739d2 Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Sun, 3 May 2020 23:50:37 -0700 Subject: [PATCH] Properly handle removal of top level items in StandardItemIconLoader The rowsAboutToBeRemoved signal from the model provides a parent index, but with QStandardItemModel, top level items are added to an invisible root item that doesn't have a valid index. This causes the range check to miss top level items due to a perceived parent mismatch. When the load completes, it attempts to access an object that has been deleted. --- src/ui/standarditemiconloader.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ui/standarditemiconloader.cpp b/src/ui/standarditemiconloader.cpp index 8e50c0359..c382e6837 100644 --- a/src/ui/standarditemiconloader.cpp +++ b/src/ui/standarditemiconloader.cpp @@ -60,12 +60,16 @@ void StandardItemIconLoader::LoadIcon(const Song& song, void StandardItemIconLoader::RowsAboutToBeRemoved(const QModelIndex& parent, int begin, int end) { + // For QStandardItemModel, the invisible root item does not have a valid index. + bool is_top = !parent.isValid(); + for (QMap::iterator it = pending_covers_.begin(); it != pending_covers_.end();) { const QStandardItem* item = it.value(); const QStandardItem* item_parent = item->parent(); - if (item_parent && item_parent->index() == parent && + if (((is_top && item_parent == nullptr) || + (item_parent != nullptr && item_parent->index() == parent)) && item->index().row() >= begin && item->index().row() <= end) { cover_loader_->CancelTask(it.key()); it = pending_covers_.erase(it);