From c62dc60ead273b1eb285bdb5665fa14769d59888 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Wed, 29 Mar 2023 23:16:33 +0200 Subject: [PATCH] Fix crash when executing the Save action Detecting aboutToClose is not enough because savingAs doesn't always go through aboutToClose it can go through swapBackingFile BUGS: 467603 --- core/document.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/core/document.cpp b/core/document.cpp index bbd3573df..92029cafd 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -4094,9 +4094,35 @@ QString Document::bookmarkedPageRange() const return range; } -struct ExecuteNextActionsHelper : public QObject { +struct ExecuteNextActionsHelper : public QObject, private DocumentObserver { Q_OBJECT public: + explicit ExecuteNextActionsHelper(Document *doc) + : m_doc(doc) + { + doc->addObserver(this); + connect(doc, &Document::aboutToClose, this, [this] { b = false; }); + } + + ~ExecuteNextActionsHelper() override + { + m_doc->removeObserver(this); + } + + void notifySetup(const QVector & /*pages*/, int setupFlags) override + { + if (setupFlags == DocumentChanged || setupFlags == UrlChanged) { + b = false; + } + } + + bool shouldExecuteNextAction() const + { + return b; + } + +private: + Document *const m_doc; bool b = true; }; @@ -4107,8 +4133,7 @@ void Document::processAction(const Action *action) } // Don't execute next actions if the action itself caused the closing of the document - ExecuteNextActionsHelper executeNextActions; - connect(this, &Document::aboutToClose, &executeNextActions, [&executeNextActions] { executeNextActions.b = false; }); + const ExecuteNextActionsHelper executeNextActionsHelper(this); switch (action->actionType()) { case Action::Goto: { @@ -4311,7 +4336,7 @@ void Document::processAction(const Action *action) } break; } - if (executeNextActions.b) { + if (executeNextActionsHelper.shouldExecuteNextAction()) { const QVector nextActions = action->nextActions(); for (const Action *a : nextActions) { processAction(a);