From 2a7f5ae886c28767e84362042014b55959878b2f Mon Sep 17 00:00:00 2001 From: emeric Date: Wed, 5 Aug 2015 12:31:57 +0200 Subject: [PATCH] [UI] Corrected crash when deleting multiple tracks from play queue --- src/ui/audio/desktop/PlayQueue.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ui/audio/desktop/PlayQueue.cpp b/src/ui/audio/desktop/PlayQueue.cpp index ab1299fe..2fa16ab7 100644 --- a/src/ui/audio/desktop/PlayQueue.cpp +++ b/src/ui/audio/desktop/PlayQueue.cpp @@ -501,12 +501,17 @@ PlayQueue::delSelected(void) int minId = _model->rowCount(); Wt::WModelIndexSet indexSet = this->selectedIndexes(); + // Make sure to delete entries in the reverse order + std::vector rowIds; for (Wt::WModelIndex index : indexSet) - { - _model->removeRow(index.row()); - if (index.row() < minId) - minId = index.row(); - } + rowIds.push_back(index.row()); + + std::sort(rowIds.begin(), rowIds.end(), std::greater()); + if (!rowIds.empty()) + minId = rowIds.back(); + + for (int rowId : rowIds) + _model->removeRow(rowId); // If the current played track is removed, make sure to unselect it _trackSelector->setSize(_model->rowCount());