fix crash in client shutdown, clean up some debugging, clean up Q_OBJECT

This commit is contained in:
ZappoMan 2014-03-17 11:01:09 -07:00
parent 96572d3752
commit 981ab7374a
6 changed files with 49 additions and 33 deletions

View file

@ -44,7 +44,7 @@ typedef std::map<QUuid, SingleSenderStats>::iterator NodeToSenderStatsMapIterato
/// Handles processing of incoming network packets for the voxel-server. As with other ReceivedPacketProcessor classes /// Handles processing of incoming network packets for the voxel-server. As with other ReceivedPacketProcessor classes
/// the user is responsible for reading inbound packets and adding them to the processing queue by calling queueReceivedPacket() /// the user is responsible for reading inbound packets and adding them to the processing queue by calling queueReceivedPacket()
class OctreeInboundPacketProcessor : public ReceivedPacketProcessor { class OctreeInboundPacketProcessor : public ReceivedPacketProcessor {
Q_OBJECT
public: public:
OctreeInboundPacketProcessor(OctreeServer* myServer); OctreeInboundPacketProcessor(OctreeServer* myServer);

View file

@ -35,11 +35,13 @@ OctreeQueryNode::OctreeQueryNode() :
_lastClientOctreeSizeScale(DEFAULT_OCTREE_SIZE_SCALE), _lastClientOctreeSizeScale(DEFAULT_OCTREE_SIZE_SCALE),
_lodChanged(false), _lodChanged(false),
_lodInitialized(false), _lodInitialized(false),
_sequenceNumber(0) _sequenceNumber(0),
_scheduleForDelete(false)
{ {
} }
OctreeQueryNode::~OctreeQueryNode() { OctreeQueryNode::~OctreeQueryNode() {
qDebug() << "OctreeQueryNode::~OctreeQueryNode()";
if (_octreeSendThread) { if (_octreeSendThread) {
_octreeSendThread->terminate(); _octreeSendThread->terminate();
delete _octreeSendThread; delete _octreeSendThread;

View file

@ -23,6 +23,7 @@ class OctreeSendThread;
class OctreeServer; class OctreeServer;
class OctreeQueryNode : public OctreeQuery { class OctreeQueryNode : public OctreeQuery {
Q_OBJECT
public: public:
OctreeQueryNode(); OctreeQueryNode();
virtual ~OctreeQueryNode(); virtual ~OctreeQueryNode();
@ -85,6 +86,9 @@ public:
void dumpOutOfView(); void dumpOutOfView();
bool isScheduledForDelete() const { return _scheduleForDelete; }
void scheduleForDelete() { _scheduleForDelete = true; }
private: private:
OctreeQueryNode(const OctreeQueryNode &); OctreeQueryNode(const OctreeQueryNode &);
OctreeQueryNode& operator= (const OctreeQueryNode&); OctreeQueryNode& operator= (const OctreeQueryNode&);
@ -119,6 +123,8 @@ private:
bool _lodInitialized; bool _lodInitialized;
OCTREE_PACKET_SEQUENCE _sequenceNumber; OCTREE_PACKET_SEQUENCE _sequenceNumber;
bool _scheduleForDelete;
}; };
#endif /* defined(__hifi__OctreeQueryNode__) */ #endif /* defined(__hifi__OctreeQueryNode__) */

View file

@ -34,7 +34,6 @@ OctreeSendThread::~OctreeSendThread() {
bool OctreeSendThread::process() { bool OctreeSendThread::process() {
const int MAX_NODE_MISSING_CHECKS = 10; const int MAX_NODE_MISSING_CHECKS = 10;
if (_nodeMissingCount > MAX_NODE_MISSING_CHECKS) { if (_nodeMissingCount > MAX_NODE_MISSING_CHECKS) {
qDebug() << "our target node:" << _nodeUUID << "has been missing the last" << _nodeMissingCount qDebug() << "our target node:" << _nodeUUID << "has been missing the last" << _nodeMissingCount
@ -64,6 +63,10 @@ bool OctreeSendThread::process() {
} }
packetsSent = packetDistributor(node, nodeData, viewFrustumChanged); packetsSent = packetDistributor(node, nodeData, viewFrustumChanged);
} }
if (nodeData->isScheduledForDelete()) {
nodeData->deleteLater();
node->setLinkedData(NULL);
}
} else { } else {
_nodeMissingCount++; _nodeMissingCount++;
} }
@ -83,7 +86,7 @@ bool OctreeSendThread::process() {
PerformanceWarning warn(false,"OctreeSendThread... usleep()",false,&_usleepTime,&_usleepCalls); PerformanceWarning warn(false,"OctreeSendThread... usleep()",false,&_usleepTime,&_usleepCalls);
usleep(usecToSleep); usleep(usecToSleep);
} else { } else {
if (true || (_myServer->wantsDebugSending() && _myServer->wantsVerboseDebug())) { if ((_myServer->wantsDebugSending() && _myServer->wantsVerboseDebug())) {
qDebug() << "Last send took too much time (" << (elapsed / USECS_PER_MSEC) qDebug() << "Last send took too much time (" << (elapsed / USECS_PER_MSEC)
<<" msecs), barely sleeping 1 usec!\n"; <<" msecs), barely sleeping 1 usec!\n";
} }
@ -576,6 +579,8 @@ int OctreeSendThread::packetDistributor(const SharedNodePointer& node, OctreeQue
quint64 elapsedInsideUsecs = endInside - startInside; quint64 elapsedInsideUsecs = endInside - startInside;
OctreeServer::trackInsideTime((float)elapsedInsideUsecs); OctreeServer::trackInsideTime((float)elapsedInsideUsecs);
const bool wantExtraDebugging = false;
if (wantExtraDebugging) {
float insideMsecs = (float)elapsedInsideUsecs / (float)USECS_PER_MSEC; float insideMsecs = (float)elapsedInsideUsecs / (float)USECS_PER_MSEC;
if (insideMsecs > 1.0f) { if (insideMsecs > 1.0f) {
qDebug()<< "inside msecs=" << insideMsecs qDebug()<< "inside msecs=" << insideMsecs
@ -585,6 +590,7 @@ int OctreeSendThread::packetDistributor(const SharedNodePointer& node, OctreeQue
<< "sending usec=" << packetSendingElapsedUsec; << "sending usec=" << packetSendingElapsedUsec;
} }
} }
}
// Here's where we can/should allow the server to send other data... // Here's where we can/should allow the server to send other data...
@ -607,6 +613,8 @@ int OctreeSendThread::packetDistributor(const SharedNodePointer& node, OctreeQue
quint64 endCompressTimeMsecs = OctreePacketData::getCompressContentTime() / 1000; quint64 endCompressTimeMsecs = OctreePacketData::getCompressContentTime() / 1000;
int elapsedCompressTimeMsecs = endCompressTimeMsecs - startCompressTimeMsecs; int elapsedCompressTimeMsecs = endCompressTimeMsecs - startCompressTimeMsecs;
bool wantsExtraDebugging = false;
if (wantsExtraDebugging) {
if (elapsedmsec > 100) { if (elapsedmsec > 100) {
if (elapsedmsec > 1000) { if (elapsedmsec > 1000) {
int elapsedsec = (end - start)/1000000; int elapsedsec = (end - start)/1000000;
@ -626,6 +634,7 @@ int OctreeSendThread::packetDistributor(const SharedNodePointer& node, OctreeQue
elapsedmsec, elapsedCompressTimeMsecs, elapsedCompressCalls, elapsedmsec, elapsedCompressTimeMsecs, elapsedCompressCalls,
trueBytesSent, truePacketsSent, nodeData->nodeBag.count()); trueBytesSent, truePacketsSent, nodeData->nodeBag.count());
} }
}
// if after sending packets we've emptied our bag, then we want to remember that we've sent all // if after sending packets we've emptied our bag, then we want to remember that we've sent all
// the voxels from the current view frustum // the voxels from the current view frustum
@ -648,9 +657,12 @@ int OctreeSendThread::packetDistributor(const SharedNodePointer& node, OctreeQue
} // end if bag wasn't empty, and so we sent stuff... } // end if bag wasn't empty, and so we sent stuff...
const bool wantExtraDebugging = false;
if (wantExtraDebugging) {
if (truePacketsSent > 0 || packetsSentThisInterval > 0) { if (truePacketsSent > 0 || packetsSentThisInterval > 0) {
qDebug() << "truePacketsSent=" << truePacketsSent << "packetsSentThisInterval=" << packetsSentThisInterval; qDebug() << "truePacketsSent=" << truePacketsSent << "packetsSentThisInterval=" << packetsSentThisInterval;
} }
}
return truePacketsSent; return truePacketsSent;
} }

View file

@ -19,6 +19,7 @@
/// Threaded processor for sending voxel packets to a single client /// Threaded processor for sending voxel packets to a single client
class OctreeSendThread : public GenericThread { class OctreeSendThread : public GenericThread {
Q_OBJECT
public: public:
OctreeSendThread(const QUuid& nodeUUID, OctreeServer* myServer); OctreeSendThread(const QUuid& nodeUUID, OctreeServer* myServer);
virtual ~OctreeSendThread(); virtual ~OctreeSendThread();

View file

@ -766,12 +766,7 @@ void OctreeServer::nodeAdded(SharedNodePointer node) {
void OctreeServer::nodeKilled(SharedNodePointer node) { void OctreeServer::nodeKilled(SharedNodePointer node) {
OctreeQueryNode* nodeData = static_cast<OctreeQueryNode*>(node->getLinkedData()); OctreeQueryNode* nodeData = static_cast<OctreeQueryNode*>(node->getLinkedData());
if (nodeData) { if (nodeData) {
// Note: It should be safe to do this without locking the node, because if any other threads nodeData->scheduleForDelete();
// are using the SharedNodePointer, then they have a reference to the SharedNodePointer and the deleteLater()
// won't actually delete it until all threads have released their references to the pointer.
// But we can and should clear the linked data so that no one else tries to access it.
nodeData->deleteLater();
node->setLinkedData(NULL);
} }
} }