History

Revert "NOT MERGEABLE: graceful cleanup on Application dtor for NodeList"

Stephen Birarda committed 11 years ago

Commit 9269b2a1 parent 4da91866 files · +34 −27Browse files

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

Unified · Split

interface/src/Application.cpp+22−18
@@ -146,6 +146,7 @@ const qint64 MAXIMUM_CACHE_SIZE = 10 * BYTES_PER_GIGABYTES; // 10GB · 145 unmodified lines
146146
147147 static QTimer* locationUpdateTimer = NULL;
148148 static QTimer* balanceUpdateTimer = NULL;
149+static QTimer* silentNodeTimer = NULL;
149150 static QTimer* identityPacketTimer = NULL;
150151 static QTimer* billboardPacketTimer = NULL;
151152 static QTimer* checkFPStimer = NULL;
@@ -257,6 +258,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 105 unmodified lines
257258 _dependencyManagerIsSetup(setupEssentials(argc, argv)),
258259 _window(new MainWindow(desktop())),
259260 _toolWindow(NULL),
261+ _nodeThread(new QThread(this)),
260262 _datagramProcessor(),
261263 _undoStack(),
262264 _undoStackScriptingInterface(&_undoStack),
@@ -327,20 +329,18 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 64 unmodified lines
327329 _runningScriptsWidget = new RunningScriptsWidget(_window);
328330
329331 // start the nodeThread so its event loop is running
330− QThread* nodeThread = new QThread(this);
331− nodeThread->setObjectName("Datagram Processor Thread");
332− nodeThread->start();
332+ _nodeThread->setObjectName("Datagram Processor Thread");
333+ _nodeThread->start();
333334
334335 // make sure the node thread is given highest priority
335− nodeThread->setPriority(QThread::TimeCriticalPriority);
336−
337− _datagramProcessor = new DatagramProcessor(nodeList.data());
336+ _nodeThread->setPriority(QThread::TimeCriticalPriority);
338337
339338 // put the NodeList and datagram processing on the node thread
340− nodeList->moveToThread(nodeThread);
339+ nodeList->moveToThread(_nodeThread);
340+ _datagramProcessor.moveToThread(_nodeThread);
341341
342342 // connect the DataProcessor processDatagrams slot to the QUDPSocket readyRead() signal
343− connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, _datagramProcessor, &DatagramProcessor::processDatagrams);
343+ connect(&nodeList->getNodeSocket(), SIGNAL(readyRead()), &_datagramProcessor, SLOT(processDatagrams()));
344344
345345 // put the audio processing on a separate thread
346346 QThread* audioThread = new QThread();
@@ -427,6 +427,12 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 80 unmodified lines
427427 // connect to the packet sent signal of the _entityEditSender
428428 connect(&_entityEditSender, &EntityEditPacketSender::packetSent, this, &Application::packetSent);
429429
430+ // move the silentNodeTimer to the _nodeThread
431+ silentNodeTimer = new QTimer();
432+ connect(silentNodeTimer, SIGNAL(timeout()), nodeList.data(), SLOT(removeSilentNodes()));
433+ silentNodeTimer->start(NODE_SILENCE_THRESHOLD_MSECS);
434+ silentNodeTimer->moveToThread(_nodeThread);
435+
430436 // send the identity packet for our avatar each second to our avatar mixer
431437 identityPacketTimer = new QTimer();
432438 connect(identityPacketTimer, &QTimer::timeout, _myAvatar, &MyAvatar::sendIdentityPacket);
@@ -541,7 +547,7 @@ void Application::aboutToQuit() { · 108 unmodified lines
541547 }
542548
543549 void Application::cleanupBeforeQuit() {
544− _datagramProcessor->shutdown(); // tell the datagram processor we're shutting down, so it can short circuit
550+ _datagramProcessor.shutdown(); // tell the datagram processor we're shutting down, so it can short circuit
545551 _entities.shutdown(); // tell the entities system we're shutting down, so it will stop running scripts
546552 ScriptEngine::stopAllScripts(this); // stop all currently running global scripts
547553
@@ -549,6 +555,7 @@ void Application::cleanupBeforeQuit() { · 1 unmodified line
549555 // depending on what thread they run in
550556 locationUpdateTimer->stop();
551557 balanceUpdateTimer->stop();
558+ QMetaObject::invokeMethod(silentNodeTimer, "stop", Qt::BlockingQueuedConnection);
552559 identityPacketTimer->stop();
553560 billboardPacketTimer->stop();
554561 checkFPStimer->stop();
@@ -558,6 +565,7 @@ void Application::cleanupBeforeQuit() { · 3 unmodified lines
558565 // and then delete those that got created by "new"
559566 delete locationUpdateTimer;
560567 delete balanceUpdateTimer;
568+ delete silentNodeTimer;
561569 delete identityPacketTimer;
562570 delete billboardPacketTimer;
563571 delete checkFPStimer;
@@ -589,6 +597,10 @@ Application::~Application() { · 25 unmodified lines
589597 tree->lockForWrite();
590598 _entities.getTree()->setSimulation(NULL);
591599 tree->unlock();
600+
601+ // ask the datagram processing thread to quit and wait until it is done
602+ _nodeThread->quit();
603+ _nodeThread->wait();
592604
593605 _octreeProcessor.terminate();
594606 _entityEditSender.terminate();
@@ -608,14 +620,6 @@ Application::~Application() { · 13 unmodified lines
608620 DependencyManager::destroy<GeometryCache>();
609621 //DependencyManager::destroy<ScriptCache>();
610622 DependencyManager::destroy<SoundCache>();
611−
612− auto nodeList = DependencyManager::get<NodeList>();
613− QThread* nodeThread = nodeList->thread();
614− nodeList->deleteLater();
615−
616− // ask the node thread to quit and wait until it is done
617− nodeThread->quit();
618− nodeThread->wait();
619623
620624 qInstallMessageHandler(NULL); // NOTE: Do this as late as possible so we continue to get our log messages
621625 }
@@ -1494,7 +1498,7 @@ void Application::checkFPS() { · 872 unmodified lines
14941498
14951499 _fps = (float)_frameCount / diffTime;
14961500 _frameCount = 0;
1497− _datagramProcessor->resetCounters();
1501+ _datagramProcessor.resetCounters();
14981502 _timerStart.start();
14991503
15001504 // ask the node list to check in with the domain server

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t