use Dependency customDeleter for Application NL

This commit is contained in:
Stephen Birarda 2015-03-12 12:27:48 -07:00
parent cd2ce2ee2f
commit 09e2c0987e
2 changed files with 10 additions and 3 deletions

View file

@ -336,6 +336,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
_datagramProcessor = new DatagramProcessor(nodeList.data()); _datagramProcessor = new DatagramProcessor(nodeList.data());
// have the NodeList use deleteLater from DM customDeleter
nodeList->setCustomDeleter([](Dependency* dependency) {
static_cast<NodeList*>(dependency)->deleteLater();
});
// 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);
@ -609,9 +614,8 @@ Application::~Application() {
//DependencyManager::destroy<ScriptCache>(); //DependencyManager::destroy<ScriptCache>();
DependencyManager::destroy<SoundCache>(); DependencyManager::destroy<SoundCache>();
auto nodeList = DependencyManager::get<NodeList>(); QThread* nodeThread = DependencyManager::get<NodeList>()->thread();
QThread* nodeThread = nodeList->thread(); DependencyManager::destroy<NodeList>();
nodeList->deleteLater();
// ask the node thread to quit and wait until it is done // ask the node thread to quit and wait until it is done
nodeThread->quit(); nodeThread->quit();

View file

@ -37,6 +37,7 @@ const quint64 DOMAIN_SERVER_CHECK_IN_MSECS = 1 * 1000;
const int MAX_SILENT_DOMAIN_SERVER_CHECK_INS = 5; const int MAX_SILENT_DOMAIN_SERVER_CHECK_INS = 5;
class Application;
class Assignment; class Assignment;
class NodeList : public LimitedNodeList { class NodeList : public LimitedNodeList {
@ -95,6 +96,8 @@ private:
HifiSockAddr _assignmentServerSocket; HifiSockAddr _assignmentServerSocket;
bool _hasCompletedInitialSTUNFailure; bool _hasCompletedInitialSTUNFailure;
unsigned int _stunRequestsSinceSuccess; unsigned int _stunRequestsSinceSuccess;
friend class Application;
}; };
#endif // hifi_NodeList_h #endif // hifi_NodeList_h