mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-10 05:37:43 +02:00
more graceful cleanup for Application NodeList and DatagramProcessor
This commit is contained in:
parent
9f754e40d0
commit
5d9a3811ca
6 changed files with 32 additions and 17 deletions
|
@ -256,7 +256,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
_dependencyManagerIsSetup(setupEssentials(argc, argv)),
|
_dependencyManagerIsSetup(setupEssentials(argc, argv)),
|
||||||
_window(new MainWindow(desktop())),
|
_window(new MainWindow(desktop())),
|
||||||
_toolWindow(NULL),
|
_toolWindow(NULL),
|
||||||
_nodeThread(new QThread(this)),
|
|
||||||
_datagramProcessor(),
|
_datagramProcessor(),
|
||||||
_undoStack(),
|
_undoStack(),
|
||||||
_undoStackScriptingInterface(&_undoStack),
|
_undoStackScriptingInterface(&_undoStack),
|
||||||
|
@ -327,18 +326,20 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
_runningScriptsWidget = new RunningScriptsWidget(_window);
|
_runningScriptsWidget = new RunningScriptsWidget(_window);
|
||||||
|
|
||||||
// start the nodeThread so its event loop is running
|
// start the nodeThread so its event loop is running
|
||||||
_nodeThread->setObjectName("Datagram Processor Thread");
|
QThread* nodeThread = new QThread();
|
||||||
_nodeThread->start();
|
nodeThread->setObjectName("Datagram Processor Thread");
|
||||||
|
nodeThread->start();
|
||||||
|
|
||||||
// make sure the node thread is given highest priority
|
// make sure the node thread is given highest priority
|
||||||
_nodeThread->setPriority(QThread::TimeCriticalPriority);
|
nodeThread->setPriority(QThread::TimeCriticalPriority);
|
||||||
|
|
||||||
|
_datagramProcessor = new DatagramProcessor(nodeList.data());
|
||||||
|
|
||||||
// put the NodeList and datagram processing on the node thread
|
// put the NodeList and datagram processing on the node thread
|
||||||
nodeList->moveToThread(_nodeThread);
|
nodeList->moveToThread(nodeThread);
|
||||||
_datagramProcessor.moveToThread(_nodeThread);
|
|
||||||
|
|
||||||
// connect the DataProcessor processDatagrams slot to the QUDPSocket readyRead() signal
|
// connect the DataProcessor processDatagrams slot to the QUDPSocket readyRead() signal
|
||||||
connect(&nodeList->getNodeSocket(), SIGNAL(readyRead()), &_datagramProcessor, SLOT(processDatagrams()));
|
connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, _datagramProcessor, &DatagramProcessor::processDatagrams);
|
||||||
|
|
||||||
// put the audio processing on a separate thread
|
// put the audio processing on a separate thread
|
||||||
QThread* audioThread = new QThread();
|
QThread* audioThread = new QThread();
|
||||||
|
@ -533,7 +534,7 @@ void Application::aboutToQuit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::cleanupBeforeQuit() {
|
void Application::cleanupBeforeQuit() {
|
||||||
_datagramProcessor.shutdown(); // tell the datagram processor we're shutting down, so it can short circuit
|
_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
|
_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
|
ScriptEngine::stopAllScripts(this); // stop all currently running global scripts
|
||||||
|
|
||||||
|
@ -581,10 +582,6 @@ Application::~Application() {
|
||||||
tree->lockForWrite();
|
tree->lockForWrite();
|
||||||
_entities.getTree()->setSimulation(NULL);
|
_entities.getTree()->setSimulation(NULL);
|
||||||
tree->unlock();
|
tree->unlock();
|
||||||
|
|
||||||
// ask the datagram processing thread to quit and wait until it is done
|
|
||||||
_nodeThread->quit();
|
|
||||||
_nodeThread->wait();
|
|
||||||
|
|
||||||
_octreeProcessor.terminate();
|
_octreeProcessor.terminate();
|
||||||
_entityEditSender.terminate();
|
_entityEditSender.terminate();
|
||||||
|
@ -603,6 +600,14 @@ Application::~Application() {
|
||||||
DependencyManager::destroy<GeometryCache>();
|
DependencyManager::destroy<GeometryCache>();
|
||||||
//DependencyManager::destroy<ScriptCache>();
|
//DependencyManager::destroy<ScriptCache>();
|
||||||
DependencyManager::destroy<SoundCache>();
|
DependencyManager::destroy<SoundCache>();
|
||||||
|
|
||||||
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
|
QThread* nodeThread = nodeList->thread();
|
||||||
|
nodeList->deleteLater();
|
||||||
|
|
||||||
|
// ask the node thread to quit and wait until it is done
|
||||||
|
nodeThread->quit();
|
||||||
|
nodeThread->wait();
|
||||||
|
|
||||||
qInstallMessageHandler(NULL); // NOTE: Do this as late as possible so we continue to get our log messages
|
qInstallMessageHandler(NULL); // NOTE: Do this as late as possible so we continue to get our log messages
|
||||||
}
|
}
|
||||||
|
@ -1459,7 +1464,7 @@ void Application::checkFPS() {
|
||||||
|
|
||||||
_fps = (float)_frameCount / diffTime;
|
_fps = (float)_frameCount / diffTime;
|
||||||
_frameCount = 0;
|
_frameCount = 0;
|
||||||
_datagramProcessor.resetCounters();
|
_datagramProcessor->resetCounters();
|
||||||
_timerStart.start();
|
_timerStart.start();
|
||||||
|
|
||||||
// ask the node list to check in with the domain server
|
// ask the node list to check in with the domain server
|
||||||
|
|
|
@ -445,10 +445,8 @@ private:
|
||||||
MainWindow* _window;
|
MainWindow* _window;
|
||||||
|
|
||||||
ToolWindow* _toolWindow;
|
ToolWindow* _toolWindow;
|
||||||
|
|
||||||
|
DatagramProcessor* _datagramProcessor;
|
||||||
QThread* _nodeThread;
|
|
||||||
DatagramProcessor _datagramProcessor;
|
|
||||||
|
|
||||||
QUndoStack _undoStack;
|
QUndoStack _undoStack;
|
||||||
UndoStackScriptingInterface _undoStackScriptingInterface;
|
UndoStackScriptingInterface _undoStackScriptingInterface;
|
||||||
|
|
|
@ -27,6 +27,10 @@ DatagramProcessor::DatagramProcessor(QObject* parent) :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DatagramProcessor::~DatagramProcessor() {
|
||||||
|
qDebug() << "DP dtor called from" << QThread::currentThread() << "and the DP thread is" << thread();
|
||||||
|
}
|
||||||
|
|
||||||
void DatagramProcessor::processDatagrams() {
|
void DatagramProcessor::processDatagrams() {
|
||||||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
||||||
"DatagramProcessor::processDatagrams()");
|
"DatagramProcessor::processDatagrams()");
|
||||||
|
|
|
@ -18,6 +18,7 @@ class DatagramProcessor : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DatagramProcessor(QObject* parent = 0);
|
DatagramProcessor(QObject* parent = 0);
|
||||||
|
~DatagramProcessor();
|
||||||
|
|
||||||
int getInPacketCount() const { return _inPacketCount; }
|
int getInPacketCount() const { return _inPacketCount; }
|
||||||
int getOutPacketCount() const { return _outPacketCount; }
|
int getOutPacketCount() const { return _outPacketCount; }
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QJsonDocument>
|
#include <QtCore/QJsonDocument>
|
||||||
#include <QtCore/QUrl>
|
#include <QtCore/QUrl>
|
||||||
|
#include <QtCore/qthread.h>
|
||||||
#include <QtNetwork/QHostInfo>
|
#include <QtNetwork/QHostInfo>
|
||||||
|
|
||||||
#include <LogHandler.h>
|
#include <LogHandler.h>
|
||||||
|
@ -62,6 +63,10 @@ NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned
|
||||||
connect(&AccountManager::getInstance(), &AccountManager::logoutComplete , this, &NodeList::reset);
|
connect(&AccountManager::getInstance(), &AccountManager::logoutComplete , this, &NodeList::reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NodeList::~NodeList() {
|
||||||
|
qDebug() << "NL dtor called from" << QThread::currentThread() << "and the NL thread is" << thread();
|
||||||
|
}
|
||||||
|
|
||||||
qint64 NodeList::sendStats(const QJsonObject& statsObject, HifiSockAddr destination) {
|
qint64 NodeList::sendStats(const QJsonObject& statsObject, HifiSockAddr destination) {
|
||||||
QByteArray statsPacket = byteArrayWithPopulatedHeader(PacketTypeNodeJsonStats);
|
QByteArray statsPacket = byteArrayWithPopulatedHeader(PacketTypeNodeJsonStats);
|
||||||
QDataStream statsPacketStream(&statsPacket, QIODevice::Append);
|
QDataStream statsPacketStream(&statsPacket, QIODevice::Append);
|
||||||
|
|
|
@ -78,6 +78,8 @@ private:
|
||||||
NodeList(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
NodeList(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||||
void operator=(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
void operator=(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||||
|
|
||||||
|
~NodeList();
|
||||||
|
|
||||||
void sendSTUNRequest();
|
void sendSTUNRequest();
|
||||||
bool processSTUNResponse(const QByteArray& packet);
|
bool processSTUNResponse(const QByteArray& packet);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue