From be74723e379d385ecbb432da3d4469bc3a75276e Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 4 Jun 2019 11:36:19 -0300 Subject: [PATCH] Destroy the data recovery before all documents We have to join the BackupObserver thread before we delete all docs, if not we could use a deleted doc when deleting/joining the backup observer thread. --- src/app/app.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index e8daaf745..95d9c24c2 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -405,11 +405,24 @@ void App::run() } #endif // ENABLE_SCRIPTING - // Destroy all documents in the UIContext. - const Docs& docs = m_modules->m_context.documents(); - while (!docs.empty()) { - Doc* doc = docs.back(); +#ifdef ENABLE_UI + if (isGui()) { + // Destroy the window. + m_mainWindow.reset(NULL); + // Delete backups (this is a normal shutdown, we are not handling + // exceptions, and we are not in a destructor). + m_modules->deleteDataRecovery(); + } +#endif + + // Destroy all documents from the UIContext. + std::vector docs; + for (Doc* doc : m_modules->m_context.closedDocs()) + docs.push_back(doc); + for (Doc* doc : m_modules->m_context.documents()) + docs.push_back(doc); + for (Doc* doc : docs) { // First we close the document. In this way we receive recent // notifications related to the document as a app::Doc. If // we delete the document directly, we destroy the app::Doc @@ -424,17 +437,6 @@ void App::run() doc->close(); delete doc; } - -#ifdef ENABLE_UI - if (isGui()) { - // Destroy the window. - m_mainWindow.reset(NULL); - - // Delete backups (this is a normal shutdown, we are not handling - // exceptions, and we are not in a destructor). - m_modules->deleteDataRecovery(); - } -#endif } // Finishes the Aseprite application.