fixes leak of GenericThread and also fixes crash in octree servers on client disconnect

This commit is contained in:
Brad Hefta-Gaub 2014-01-16 12:53:32 -08:00
parent b4c963b9f8
commit f97ab1dafe
4 changed files with 29 additions and 21 deletions

View file

@ -1427,13 +1427,14 @@ void Application::terminate() {
// let the avatar mixer know we're out
NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1);
printf("");
//printf("");
_voxelProcessor.terminate();
_voxelHideShowThread.terminate();
_voxelEditSender.terminate();
_particleEditSender.terminate();
if (_persistThread) {
_persistThread->terminate();
_persistThread->deleteLater();
_persistThread = NULL;
}
}
@ -4395,6 +4396,7 @@ void Application::updateLocalOctreeCache(bool firstTime) {
if (_persistThread) {
_persistThread->terminate();
_persistThread->deleteLater();
_persistThread = NULL;
}

View file

@ -158,13 +158,13 @@ void OctreeQueryNode::writeToPacket(const unsigned char* buffer, int bytes) {
}
OctreeQueryNode::~OctreeQueryNode() {
delete[] _octreePacket;
delete[] _lastOctreePacket;
if (_octreeSendThread) {
_octreeSendThread->terminate();
delete _octreeSendThread;
_octreeSendThread->deleteLater();
}
delete[] _octreePacket;
delete[] _lastOctreePacket;
}
bool OctreeQueryNode::updateCurrentViewFrustum() {

View file

@ -75,17 +75,17 @@ OctreeServer::~OctreeServer() {
if (_jurisdictionSender) {
_jurisdictionSender->terminate();
delete _jurisdictionSender;
_jurisdictionSender->deleteLater();
}
if (_octreeInboundPacketProcessor) {
_octreeInboundPacketProcessor->terminate();
delete _octreeInboundPacketProcessor;
_octreeInboundPacketProcessor->deleteLater();
}
if (_persistThread) {
_persistThread->terminate();
delete _persistThread;
_persistThread->deleteLater();
}
delete _jurisdiction;
@ -593,7 +593,7 @@ void OctreeServer::run() {
setvbuf(stdout, NULL, _IOLBF, 0);
// tell our NodeList about our desire to get notifications
connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer)));
connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), this, SLOT(nodeKilled(SharedNodePointer)));
nodeList->linkedDataCreateCallback = &OctreeServer::attachQueryNodeToNode;
srand((unsigned)time(0));

View file

@ -8,8 +8,11 @@
// Generic Threaded or non-threaded processing class
//
#include <QDebug>
#include "GenericThread.h"
GenericThread::GenericThread() :
_stopThread(false),
_isThreaded(false) // assume non-threaded, must call initialize()
@ -23,15 +26,11 @@ GenericThread::~GenericThread() {
void GenericThread::initialize(bool isThreaded) {
_isThreaded = isThreaded;
if (_isThreaded) {
QThread* _thread = new QThread(this);
_thread = new QThread(this);
// when the worker thread is started, call our engine's run..
connect(_thread, SIGNAL(started()), this, SLOT(threadRoutine()));
// XXXBHG: this is a known memory leak/thread leak. I will fix this shortly.
//connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
//connect(_thread, SIGNAL(finished()), _thread, SLOT(deleteLater()));
this->moveToThread(_thread);
// Starts an event loop, and emits _thread->started()
@ -42,7 +41,11 @@ void GenericThread::initialize(bool isThreaded) {
void GenericThread::terminate() {
if (_isThreaded) {
_stopThread = true;
//_isThreaded = false;
if (_thread) {
_thread->wait();
_thread->deleteLater();
}
}
}
@ -61,7 +64,10 @@ void GenericThread::threadRoutine() {
}
}
if (_isThreaded) {
// If we were on a thread, then wait till it's done
if (_isThreaded && _thread) {
_thread->quit();
}
emit finished();
}
}