diff --git a/src/platform/qt/GBAApp.cpp b/src/platform/qt/GBAApp.cpp index 39f85723b..823f3f773 100644 --- a/src/platform/qt/GBAApp.cpp +++ b/src/platform/qt/GBAApp.cpp @@ -64,10 +64,20 @@ GBAApp::GBAApp(int& argc, char* argv[], ConfigController* config) if (!m_configController->getQtOption("audioDriver").isNull()) { AudioProcessor::setDriver(static_cast(m_configController->getQtOption("audioDriver").toInt())); } + + connect(this, &GBAApp::aboutToQuit, this, &GBAApp::cleanup); } -GBAApp::~GBAApp() { +void GBAApp::cleanup() { m_workerThreads.waitForDone(); + + while (!m_workerJobs.isEmpty()) { + finishJob(m_workerJobs.firstKey()); + } + + if (m_db) { + NoIntroDBDestroy(m_db); + } } bool GBAApp::event(QEvent* event) { @@ -177,7 +187,7 @@ bool GBAApp::reloadGameDB() { NoIntroDBDestroy(m_db); } if (db) { - GameDBParser* parser = new GameDBParser(db); + std::shared_ptr parser = std::make_shared(db); submitWorkerJob(std::bind(&GameDBParser::parseNoIntroDB, parser)); m_db = db; return true; diff --git a/src/platform/qt/GBAApp.h b/src/platform/qt/GBAApp.h index 2e2c02af2..0ce099f33 100644 --- a/src/platform/qt/GBAApp.h +++ b/src/platform/qt/GBAApp.h @@ -52,7 +52,6 @@ Q_OBJECT public: GBAApp(int& argc, char* argv[], ConfigController*); - ~GBAApp(); static GBAApp* app(); static QString dataDir(); @@ -79,6 +78,7 @@ protected: private slots: void finishJob(qint64 jobId); + void cleanup(); private: class WorkerJob : public QRunnable {