From d659ac573a963b2494675ce5b2264b3e53364f4d Mon Sep 17 00:00:00 2001 From: Kai Ludwig Date: Wed, 18 Feb 2015 19:53:45 +0100 Subject: [PATCH] now all application timers should get stopped correctly on exit --- interface/src/Application.cpp | 45 ++++++++++++++++++++++++++--------- interface/src/Application.h | 2 +- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d1558c3799..855eb5e1ba 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -139,6 +139,12 @@ static unsigned STARFIELD_SEED = 1; const qint64 MAXIMUM_CACHE_SIZE = 10737418240; // 10GB +static QTimer* locationUpdateTimer = NULL; +static QTimer* balanceUpdateTimer = NULL; +static QTimer* silentNodeTimer = NULL; +static QTimer* identityPacketTimer = NULL; +static QTimer* billboardPacketTimer = NULL; +static QTimer* checkFPStimer = NULL; static QTimer* idleTimer = NULL; const QString CHECK_VERSION_URL = "https://highfidelity.io/latestVersion.xml"; @@ -361,7 +367,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : // update our location every 5 seconds in the data-server, assuming that we are authenticated with one const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * 1000; - QTimer* locationUpdateTimer = new QTimer(this); + locationUpdateTimer = new QTimer(this); connect(locationUpdateTimer, &QTimer::timeout, this, &Application::updateLocationInServer); locationUpdateTimer->start(DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS); @@ -377,7 +383,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : const qint64 BALANCE_UPDATE_INTERVAL_MSECS = 5 * 1000; - QTimer* balanceUpdateTimer = new QTimer(this); + balanceUpdateTimer = new QTimer(this); connect(balanceUpdateTimer, &QTimer::timeout, &accountManager, &AccountManager::updateBalance); balanceUpdateTimer->start(BALANCE_UPDATE_INTERVAL_MSECS); @@ -416,18 +422,18 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : connect(&_entityEditSender, &EntityEditPacketSender::packetSent, this, &Application::packetSent); // move the silentNodeTimer to the _nodeThread - QTimer* silentNodeTimer = new QTimer(); + silentNodeTimer = new QTimer(); connect(silentNodeTimer, SIGNAL(timeout()), nodeList.data(), SLOT(removeSilentNodes())); silentNodeTimer->start(NODE_SILENCE_THRESHOLD_MSECS); silentNodeTimer->moveToThread(_nodeThread); // send the identity packet for our avatar each second to our avatar mixer - QTimer* identityPacketTimer = new QTimer(); + identityPacketTimer = new QTimer(); connect(identityPacketTimer, &QTimer::timeout, _myAvatar, &MyAvatar::sendIdentityPacket); identityPacketTimer->start(AVATAR_IDENTITY_PACKET_SEND_INTERVAL_MSECS); // send the billboard packet for our avatar every few seconds - QTimer* billboardPacketTimer = new QTimer(); + billboardPacketTimer = new QTimer(); connect(billboardPacketTimer, &QTimer::timeout, _myAvatar, &MyAvatar::sendBillboardPacket); billboardPacketTimer->start(AVATAR_BILLBOARD_PACKET_SEND_INTERVAL_MSECS); @@ -526,11 +532,28 @@ void Application::aboutToQuit() { } void Application::cleanupBeforeQuit() { - // make sure we don't call the idle timer any more + // first stop all timers directly or by invokeMethod + // depending on what thread they run in + locationUpdateTimer->stop(); + balanceUpdateTimer->stop(); + QMetaObject::invokeMethod(silentNodeTimer, "stop", Qt::BlockingQueuedConnection); + identityPacketTimer->stop(); + billboardPacketTimer->stop(); + checkFPStimer->stop(); + idleTimer->stop(); + QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection); + + // and then delete those that got created by "new" + delete locationUpdateTimer; + delete balanceUpdateTimer; + delete silentNodeTimer; + delete identityPacketTimer; + delete billboardPacketTimer; + delete checkFPStimer; delete idleTimer; + // no need to delete _settingsTimer here as it is no pointer // save state - QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection); _settingsThread.quit(); saveSettings(); _window->saveGeometry(); @@ -629,9 +652,9 @@ void Application::initializeGL() { _entityEditSender.initialize(_enableProcessOctreeThread); // call our timer function every second - QTimer* timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), SLOT(timer())); - timer->start(1000); + checkFPStimer = new QTimer(this); + connect(checkFPStimer, SIGNAL(timeout()), SLOT(checkFPS())); + checkFPStimer->start(1000); // call our idle function whenever we can idleTimer = new QTimer(this); @@ -1427,7 +1450,7 @@ void Application::sendPingPackets() { } // Every second, check the frame rates and other stuff -void Application::timer() { +void Application::checkFPS() { if (Menu::getInstance()->isOptionChecked(MenuOption::TestPing)) { sendPingPackets(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index da29920ef9..f5c5397f6e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -368,7 +368,7 @@ public slots: private slots: void clearDomainOctreeDetails(); - void timer(); + void checkFPS(); void idle(); void aboutToQuit();