fix octree-server random spinout sometimes when client disconnects

This commit is contained in:
ZappoMan 2014-02-27 16:13:05 -08:00
parent 348295bbb1
commit f9718913e2
3 changed files with 28 additions and 11 deletions

View file

@ -37,6 +37,18 @@ OctreeQueryNode::OctreeQueryNode() :
_sequenceNumber = 0;
}
OctreeQueryNode::~OctreeQueryNode() {
if (_octreeSendThread) {
_octreeSendThread->terminate();
delete _octreeSendThread;
}
delete[] _octreePacket;
delete[] _lastOctreePacket;
}
void OctreeQueryNode::initializeOctreeSendThread(OctreeServer* octreeServer, const QUuid& nodeUUID) {
// Create octree sending thread...
_octreeSendThread = new OctreeSendThread(nodeUUID, octreeServer);
@ -158,16 +170,6 @@ void OctreeQueryNode::writeToPacket(const unsigned char* buffer, int bytes) {
}
}
OctreeQueryNode::~OctreeQueryNode() {
if (_octreeSendThread) {
_octreeSendThread->terminate();
delete _octreeSendThread;
}
delete[] _octreePacket;
delete[] _lastOctreePacket;
}
bool OctreeQueryNode::updateCurrentViewFrustum() {
bool currentViewFrustumChanged = false;
ViewFrustum newestViewFrustum;

View file

@ -20,7 +20,8 @@ quint64 endSceneSleepTime = 0;
OctreeSendThread::OctreeSendThread(const QUuid& nodeUUID, OctreeServer* myServer) :
_nodeUUID(nodeUUID),
_myServer(myServer),
_packetData()
_packetData(),
_nodeMissingCount(0)
{
qDebug() << "client connected";
_myServer->clientConnected();
@ -33,6 +34,14 @@ OctreeSendThread::~OctreeSendThread() {
bool OctreeSendThread::process() {
const int MAX_NODE_MISSING_CHECKS = 10;
if (_nodeMissingCount > MAX_NODE_MISSING_CHECKS) {
qDebug() << "our target node:" << _nodeUUID << "has been missing the last" << _nodeMissingCount
<< "times we checked, we are going to stop attempting to send.";
return false; // stop processing and shutdown, our node no longer exists
}
quint64 start = usecTimestampNow();
bool gotLock = false;
@ -41,6 +50,7 @@ bool OctreeSendThread::process() {
SharedNodePointer node = NodeList::getInstance()->nodeWithUUID(_nodeUUID);
if (node) {
_nodeMissingCount = 0;
// make sure the node list doesn't kill our node while we're using it
if (node->getMutex().tryLock()) {
gotLock = true;
@ -61,6 +71,8 @@ bool OctreeSendThread::process() {
node->getMutex().unlock(); // we're done with this node for now.
}
} else {
_nodeMissingCount++;
}
} else {
if (_myServer->wantsDebugSending() && _myServer->wantsVerboseDebug()) {

View file

@ -16,6 +16,7 @@
#include "OctreeQueryNode.h"
#include "OctreeServer.h"
/// Threaded processor for sending voxel packets to a single client
class OctreeSendThread : public GenericThread {
public:
@ -41,6 +42,8 @@ private:
int packetDistributor(const SharedNodePointer& node, OctreeQueryNode* nodeData, bool viewFrustumChanged);
OctreePacketData _packetData;
int _nodeMissingCount;
};
#endif // __octree_server__OctreeSendThread__