Skip to content

Commit

Permalink
Properly handle removal of top level items in StandardItemIconLoader
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jbroadus authored and hatstand committed May 4, 2020
1 parent dc42700 commit 7e7d271
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ui/standarditemiconloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<quint64, QStandardItem*>::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);
Expand Down

0 comments on commit 7e7d271

Please sign in to comment.