qt: Fix save manager crash when deleting multiple entries (#19019)

This commit is contained in:
Jordan Jones
2026-07-17 07:27:07 -04:00
committed by GitHub
parent 95da0365a3
commit 430984729d
+18 -8
View File
@@ -573,26 +573,36 @@ void save_manager_dialog::OnEntryRemove(int row, bool user_interaction)
void save_manager_dialog::OnEntriesRemove() void save_manager_dialog::OnEntriesRemove()
{ {
QModelIndexList selection(m_list->selectionModel()->selectedRows()); const QModelIndexList selected_rows(m_list->selectionModel()->selectedRows());
if (selection.empty()) if (selected_rows.empty())
{ {
return; return;
} }
// Collect row indices as plain ints BEFORE any model modification.
// QModelIndex references can become stale after removeRow() below.
std::vector<int> rows;
rows.reserve(selected_rows.size());
for (const QModelIndex& index : selected_rows)
{
rows.push_back(index.row());
}
WaitForRepaintThreads(false); WaitForRepaintThreads(false);
if (selection.size() == 1) if (rows.size() == 1)
{ {
OnEntryRemove(selection.first().row(), true); OnEntryRemove(rows.front(), true);
return; return;
} }
if (QMessageBox::question(this, tr("Delete Confirmation"), tr("Are you sure you want to delete these %n items?", "", selection.size()), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) if (QMessageBox::question(this, tr("Delete Confirmation"), tr("Are you sure you want to delete these %n items?", "", rows.size()), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
{ {
std::sort(selection.rbegin(), selection.rend()); // Sort descending so removeRow() doesn't shift remaining indices.
for (const QModelIndex& index : selection) std::sort(rows.begin(), rows.end(), std::greater<int>());
for (int row : rows)
{ {
OnEntryRemove(index.row(), false); OnEntryRemove(row, false);
} }
} }
} }