From bdcca9cbf4319f76251bdce58de13727c31c3cbf Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 23 Jan 2014 14:57:32 -0800 Subject: [PATCH] fix random crash on interface shutdown --- interface/src/VoxelHideShowThread.cpp | 1 + libraries/octree/src/JurisdictionListener.cpp | 3 +++ libraries/octree/src/OctreePersistThread.cpp | 1 + libraries/shared/src/GenericThread.cpp | 11 ++++++++++- libraries/shared/src/PacketSender.cpp | 1 + libraries/shared/src/ReceivedPacketProcessor.cpp | 1 + 6 files changed, 17 insertions(+), 1 deletion(-) diff --git a/interface/src/VoxelHideShowThread.cpp b/interface/src/VoxelHideShowThread.cpp index 2a42db7f70..a568edfc8e 100644 --- a/interface/src/VoxelHideShowThread.cpp +++ b/interface/src/VoxelHideShowThread.cpp @@ -18,6 +18,7 @@ VoxelHideShowThread::VoxelHideShowThread(VoxelSystem* theSystem) : _theSystem(theSystem) { + //qDebug() << "VoxelHideShowThread::VoxelHideShowThread() this=" << this; } bool VoxelHideShowThread::process() { diff --git a/libraries/octree/src/JurisdictionListener.cpp b/libraries/octree/src/JurisdictionListener.cpp index d8686debad..056f4508da 100644 --- a/libraries/octree/src/JurisdictionListener.cpp +++ b/libraries/octree/src/JurisdictionListener.cpp @@ -18,6 +18,9 @@ JurisdictionListener::JurisdictionListener(NODE_TYPE type, PacketSenderNotify* notify) : _packetSender(notify, JurisdictionListener::DEFAULT_PACKETS_PER_SECOND) { + //qDebug() << "JurisdictionListener::JurisdictionListener() this=" << this; + //qDebug() << "JurisdictionListener::JurisdictionListener() this=" << this << " _packetSender=" << &_packetSender; + _nodeType = type; ReceivedPacketProcessor::_dontSleep = true; // we handle sleeping so this class doesn't need to diff --git a/libraries/octree/src/OctreePersistThread.cpp b/libraries/octree/src/OctreePersistThread.cpp index 052773f475..ea85c6e178 100644 --- a/libraries/octree/src/OctreePersistThread.cpp +++ b/libraries/octree/src/OctreePersistThread.cpp @@ -20,6 +20,7 @@ OctreePersistThread::OctreePersistThread(Octree* tree, const QString& filename, _persistInterval(persistInterval), _initialLoadComplete(false), _loadTimeUSecs(0) { + //qDebug() << "OctreePersistThread::OctreePersistThread()... this=" << this; } bool OctreePersistThread::process() { diff --git a/libraries/shared/src/GenericThread.cpp b/libraries/shared/src/GenericThread.cpp index a2dcf1004d..23d3649544 100644 --- a/libraries/shared/src/GenericThread.cpp +++ b/libraries/shared/src/GenericThread.cpp @@ -17,10 +17,16 @@ GenericThread::GenericThread() : _stopThread(false), _isThreaded(false) // assume non-threaded, must call initialize() { + //qDebug() << "GenericThread::GenericThread() this=" << this; } GenericThread::~GenericThread() { - terminate(); + //qDebug() << "GenericThread::~GenericThread() this=" << this; + + // we only need to call terminate() if we're actually threaded and still running + if (isStillRunning() && isThreaded()) { + terminate(); + } } void GenericThread::initialize(bool isThreaded) { @@ -39,12 +45,14 @@ void GenericThread::initialize(bool isThreaded) { } void GenericThread::terminate() { + //qDebug() << "GenericThread::terminate()... this=" << this; if (_isThreaded) { _stopThread = true; if (_thread) { _thread->wait(); _thread->deleteLater(); + _thread = NULL; } } } @@ -66,6 +74,7 @@ void GenericThread::threadRoutine() { // If we were on a thread, then quit our thread if (_isThreaded && _thread) { + //qDebug() << "GenericThread::threadRoutine()... about to call _thread->quit() this=" << this << " _thread=" << _thread; _thread->quit(); } diff --git a/libraries/shared/src/PacketSender.cpp b/libraries/shared/src/PacketSender.cpp index ce720bf447..7d4680985c 100644 --- a/libraries/shared/src/PacketSender.cpp +++ b/libraries/shared/src/PacketSender.cpp @@ -42,6 +42,7 @@ PacketSender::PacketSender(PacketSenderNotify* notify, int packetsPerSecond) : _totalPacketsQueued(0), _totalBytesQueued(0) { + //qDebug() << "PacketSender::PacketSender()... this=" << this; } PacketSender::~PacketSender() { diff --git a/libraries/shared/src/ReceivedPacketProcessor.cpp b/libraries/shared/src/ReceivedPacketProcessor.cpp index d61db2b184..8d0a4f8280 100644 --- a/libraries/shared/src/ReceivedPacketProcessor.cpp +++ b/libraries/shared/src/ReceivedPacketProcessor.cpp @@ -14,6 +14,7 @@ ReceivedPacketProcessor::ReceivedPacketProcessor() { _dontSleep = false; + //qDebug() << "ReceivedPacketProcessor::ReceivedPacketProcessor()... this=" << this; } void ReceivedPacketProcessor::queueReceivedPacket(const HifiSockAddr& address, unsigned char* packetData, ssize_t packetLength) {