From 96c053e42bc4ec8785b295214462bee7ad212ae8 Mon Sep 17 00:00:00 2001 From: xiaozhaoGithub <1085080350@qq.com> Date: Tue, 24 Oct 2023 17:43:56 +0800 Subject: [PATCH] fix: fix the crash caused by assertion 1. The internal implementation of the qt function beginRemoveRows, including the assertion judgment: Q_ASSERT(last < rowCount(parent)); --- app/undo/undostack.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/undo/undostack.cpp b/app/undo/undostack.cpp index ec7f39f765..eb7dee71b0 100644 --- a/app/undo/undostack.cpp +++ b/app/undo/undostack.cpp @@ -68,14 +68,14 @@ void UndoStack::push(UndoCommand *command, const QString &name) } // Clear any redoable commands - this->beginRemoveRows(QModelIndex(), commands_.size(), commands_.size() + undone_commands_.size()); if (CanRedo()) { + this->beginRemoveRows(QModelIndex(), commands_.size(), commands_.size() + undone_commands_.size() - 1); for (auto it=undone_commands_.cbegin(); it!=undone_commands_.cend(); it++) { delete (*it).command; } undone_commands_.clear(); + this->endRemoveRows(); } - this->endRemoveRows(); // Do command and push this->beginInsertRows(QModelIndex(), commands_.size(), commands_.size());