From 0835bc27d6c2949759c3e125587e3448e25745b7 Mon Sep 17 00:00:00 2001 From: letsfindaway Date: Fri, 25 Oct 2024 17:22:27 +0200 Subject: [PATCH] fix: crash when closing while scene is loading - OpenBoard crashes when it is terminated while a scene is loading in background - the timer used for background loading still runs and accesses resources no longer available - add a flag isClosing to UBApplication - check flag in timer routine in UBSceneCache --- src/core/UBApplication.cpp | 4 ++++ src/core/UBApplication.h | 2 ++ src/core/UBSceneCache.cpp | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/src/core/UBApplication.cpp b/src/core/UBApplication.cpp index 9e74e09a3..e7d7853ab 100644 --- a/src/core/UBApplication.cpp +++ b/src/core/UBApplication.cpp @@ -79,6 +79,8 @@ UBDocumentController* UBApplication::documentController = 0; UBMainWindow* UBApplication::mainWindow = 0; +bool UBApplication::isClosing = false; + const QString UBApplication::mimeTypeUniboardDocument = QString("application/vnd.mnemis-uniboard-document"); const QString UBApplication::mimeTypeUniboardPage = QString("application/vnd.mnemis-uniboard-page"); const QString UBApplication::mimeTypeUniboardPageItem = QString("application/vnd.mnemis-uniboard-page-item"); @@ -507,6 +509,8 @@ void UBApplication::closeEvent(QCloseEvent *event) void UBApplication::closing() { + isClosing = true; + if (UBSettings::settings()->emptyTrashForOlderDocuments->get().toBool()) { UBDocumentTreeModel *docModel = UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel; diff --git a/src/core/UBApplication.h b/src/core/UBApplication.h index 9347c5b63..ab13cf832 100644 --- a/src/core/UBApplication.h +++ b/src/core/UBApplication.h @@ -78,6 +78,8 @@ class UBApplication : public SingleApplication static UBMainWindow* mainWindow; + static bool isClosing; + static UBApplication* app() { return dynamic_castqApp; diff --git a/src/core/UBSceneCache.cpp b/src/core/UBSceneCache.cpp index a1c788cdc..fb5896d3a 100644 --- a/src/core/UBSceneCache.cpp +++ b/src/core/UBSceneCache.cpp @@ -322,6 +322,13 @@ void UBSceneCache::SceneCacheEntry::startLoading() { mTimer = new QTimer; QObject::connect(mTimer, &QTimer::timeout, mTimer, [this](){ + if (UBApplication::isClosing) + { + mTimer->stop(); + delete mTimer; + return; + } + if (mContext) { mContext->step();