History

Merge branch 'master' of git://github.com/highfidelity/hifi into 21378

Olivier Prat committed 9 years ago

Commit 5cee2cf2 parents 45342a0 fad686571 files · +1051 −495Browse files

Showing the changes to interface/src/Application.cpp (1 of 71 files). Show all

Unified · Split

interface/src/Application.cpp+29−16
@@ -48,6 +48,7 @@ · 47 unmodified lines
4848
4949 #include <gl/QOpenGLContextWrapper.h>
5050
51+#include <shared/QtHelpers.h>
5152 #include <shared/GlobalAppProperties.h>
5253 #include <StatTracker.h>
5354 #include <Trace.h>
@@ -1209,15 +1210,26 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 1155 unmodified lines
12091210 // Make sure we don't time out during slow operations at startup
12101211 updateHeartbeat();
12111212
1212− int SAVE_SETTINGS_INTERVAL = 10 * MSECS_PER_SECOND; // Let's save every seconds for now
1213− connect(&_settingsTimer, &QTimer::timeout, this, &Application::saveSettings);
1214− connect(&_settingsThread, SIGNAL(started()), &_settingsTimer, SLOT(start()));
1215− connect(&_settingsThread, SIGNAL(finished()), &_settingsTimer, SLOT(stop()));
1216− _settingsTimer.moveToThread(&_settingsThread);
1217− _settingsTimer.setSingleShot(false);
1218− _settingsTimer.setInterval(SAVE_SETTINGS_INTERVAL); // 10s, Qt::CoarseTimer acceptable
1219− _settingsThread.setPriority(QThread::LowestPriority);
1220− _settingsThread.start();
1213+
1214+ QTimer* settingsTimer = new QTimer();
1215+ moveToNewNamedThread(settingsTimer, "Settings Thread", [this, settingsTimer]{
1216+ connect(qApp, &Application::beforeAboutToQuit, [this, settingsTimer]{
1217+ // Disconnect the signal from the save settings
1218+ QObject::disconnect(settingsTimer, &QTimer::timeout, this, &Application::saveSettings);
1219+ // Stop the settings timer
1220+ settingsTimer->stop();
1221+ // Delete it (this will trigger the thread destruction
1222+ settingsTimer->deleteLater();
1223+ // Mark the settings thread as finished, so we know we can safely save in the main application
1224+ // shutdown code
1225+ _settingsGuard.trigger();
1226+ });
1227+
1228+ int SAVE_SETTINGS_INTERVAL = 10 * MSECS_PER_SECOND; // Let's save every seconds for now
1229+ settingsTimer->setSingleShot(false);
1230+ settingsTimer->setInterval(SAVE_SETTINGS_INTERVAL); // 10s, Qt::CoarseTimer acceptable
1231+ QObject::connect(settingsTimer, &QTimer::timeout, this, &Application::saveSettings);
1232+ }, QThread::LowestPriority);
12211233
12221234 if (Menu::getInstance()->isOptionChecked(MenuOption::FirstPerson)) {
12231235 getMyAvatar()->setBoomLength(MyAvatar::ZOOM_MIN); // So that camera doesn't auto-switch to third person.
@@ -1645,7 +1657,7 @@ QString Application::getUserAgent() { · 421 unmodified lines
16451657 if (QThread::currentThread() != thread()) {
16461658 QString userAgent;
16471659
1648− QMetaObject::invokeMethod(this, "getUserAgent", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QString, userAgent));
1660+ BLOCKING_INVOKE_METHOD(this, "getUserAgent", Q_RETURN_ARG(QString, userAgent));
16491661
16501662 return userAgent;
16511663 }
@@ -1803,11 +1815,13 @@ void Application::cleanupBeforeQuit() { · 151 unmodified lines
18031815 locationUpdateTimer.stop();
18041816 identityPacketTimer.stop();
18051817 pingTimer.stop();
1806− QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection);
18071818
1808− // save state
1809− _settingsThread.quit();
1810− saveSettings();
1819+ // Wait for the settings thread to shut down, and save the settings one last time when it's safe
1820+ if (_settingsGuard.wait()) {
1821+ // save state
1822+ saveSettings();
1823+ }
1824+
18111825 _window->saveGeometry();
18121826
18131827 // Destroy third party processes after scripts have finished using them.
@@ -1831,8 +1845,7 @@ void Application::cleanupBeforeQuit() { · 17 unmodified lines
18311845
18321846 // FIXME: something else is holding a reference to AudioClient,
18331847 // so it must be explicitly synchronously stopped here
1834− QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
1835− "cleanupBeforeQuit", Qt::BlockingQueuedConnection);
1848+ DependencyManager::get<AudioClient>()->cleanupBeforeQuit();
18361849
18371850 // destroy Audio so it and its threads have a chance to go down safely
18381851 // this must happen after QML, as there are unexplained audio crashes originating in qtwebengine