From e66f12f95873728e773db1be8b46089b6df4735a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 25 Feb 2015 10:56:08 -0800 Subject: [PATCH] add shutdown short circuiting to datagram processor --- interface/src/Application.cpp | 5 +++-- interface/src/DatagramProcessor.cpp | 4 ++++ interface/src/DatagramProcessor.h | 11 +++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d3161ebf51..eb228f2874 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -534,6 +534,7 @@ void Application::aboutToQuit() { void Application::cleanupBeforeQuit() { + _datagramProcessor.shutdown(); // tell the datagram processor we're shutting down, so it can short circuit _entities.shutdown(); // tell the entities system we're shutting down, so it will stop running scripts ScriptEngine::stopAllScripts(this); // stop all currently running global scripts @@ -584,8 +585,6 @@ Application::~Application() { _entities.getTree()->setSimulation(NULL); tree->unlock(); - qInstallMessageHandler(NULL); - // ask the datagram processing thread to quit and wait until it is done _nodeThread->quit(); _nodeThread->wait(); @@ -606,6 +605,8 @@ Application::~Application() { DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); + + qInstallMessageHandler(NULL); // NOTE: Do this as late as possible so we continue to get our log messages } void Application::initializeGL() { diff --git a/interface/src/DatagramProcessor.cpp b/interface/src/DatagramProcessor.cpp index 02d3c62765..a491f9444d 100644 --- a/interface/src/DatagramProcessor.cpp +++ b/interface/src/DatagramProcessor.cpp @@ -30,6 +30,10 @@ DatagramProcessor::DatagramProcessor(QObject* parent) : void DatagramProcessor::processDatagrams() { PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "DatagramProcessor::processDatagrams()"); + + if (_isShuttingDown) { + return; // bail early... we're shutting down. + } HifiSockAddr senderSockAddr; diff --git a/interface/src/DatagramProcessor.h b/interface/src/DatagramProcessor.h index 4ce090e52e..7fc192ee2d 100644 --- a/interface/src/DatagramProcessor.h +++ b/interface/src/DatagramProcessor.h @@ -25,14 +25,17 @@ public: int getOutByteCount() const { return _outByteCount; } void resetCounters() { _inPacketCount = 0; _outPacketCount = 0; _inByteCount = 0; _outByteCount = 0; } + + void shutdown() { _isShuttingDown = true; } public slots: void processDatagrams(); private: - int _inPacketCount; - int _outPacketCount; - int _inByteCount; - int _outByteCount; + int _inPacketCount = 0; + int _outPacketCount = 0; + int _inByteCount = 0; + int _outByteCount = 0; + bool _isShuttingDown = false; }; #endif // hifi_DatagramProcessor_h