From 30087bb34dce03f113a0dd61f5fc675628a945c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= Date: Tue, 8 Jun 2021 16:12:29 +0200 Subject: [PATCH] fixed a crash that would randomly occur when performing multiple deletion inside the trash --- src/document/UBDocumentController.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index 60a56854..e6520b9c 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -2762,10 +2762,11 @@ void UBDocumentController::deleteIndexAndAssociatedData(const QModelIndex &pInde } //N/C - NNE - 20140408 + UBDocumentProxy *proxyData = nullptr; if(pIndex.column() == 0) { if (docModel->isDocument(pIndex)) { - UBDocumentProxy *proxyData = docModel->proxyData(pIndex); + proxyData = docModel->proxyData(pIndex); if (selectedDocument() == proxyData) { @@ -2778,7 +2779,15 @@ void UBDocumentController::deleteIndexAndAssociatedData(const QModelIndex &pInde } } - docModel->removeRow(pIndex.row(), pIndex.parent()); + if (proxyData) + { + // need to recall indexForProxy as rows could have changed when performing a multiple deletion + QModelIndex indexForProxy = docModel->indexForProxy(proxyData); + if (!docModel->removeRow(indexForProxy.row(), indexForProxy.parent())) + { + qDebug() << "could not remove row (r:" << indexForProxy.row() << "p:" << indexForProxy.parent() << ")"; + } + } }