From 05a38a78c517db0b3c646eac24ca9b1cb7824d57 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 14 Nov 2017 14:08:27 -0800 Subject: [PATCH 1/2] don't send octree data without first query --- assignment-client/src/octree/OctreeSendThread.cpp | 5 +++-- libraries/octree/src/OctreeQuery.h | 2 +- libraries/octree/src/OctreeQueryNode.cpp | 6 ++++++ libraries/octree/src/OctreeQueryNode.h | 6 ++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/assignment-client/src/octree/OctreeSendThread.cpp b/assignment-client/src/octree/OctreeSendThread.cpp index 89e3d403fc..024071db0a 100644 --- a/assignment-client/src/octree/OctreeSendThread.cpp +++ b/assignment-client/src/octree/OctreeSendThread.cpp @@ -82,8 +82,9 @@ bool OctreeSendThread::process() { if (auto node = _node.lock()) { OctreeQueryNode* nodeData = static_cast(node->getLinkedData()); - // Sometimes the node data has not yet been linked, in which case we can't really do anything - if (nodeData && !nodeData->isShuttingDown()) { + // If we don't have the OctreeQueryNode or it's uninitialized because we haven't received + // a query yet from the client then we can't send an entity data packet + if (nodeData && nodeData->hasReceivedFirstQuery() && !nodeData->isShuttingDown()) { bool viewFrustumChanged = nodeData->updateCurrentViewFrustum(); packetDistributor(node, nodeData, viewFrustumChanged); } diff --git a/libraries/octree/src/OctreeQuery.h b/libraries/octree/src/OctreeQuery.h index fc9ea525e6..bbd0350baf 100644 --- a/libraries/octree/src/OctreeQuery.h +++ b/libraries/octree/src/OctreeQuery.h @@ -31,7 +31,7 @@ public: virtual ~OctreeQuery() {} int getBroadcastData(unsigned char* destinationBuffer); - int parseData(ReceivedMessage& message) override; + virtual int parseData(ReceivedMessage& message) override; // getters for camera details const glm::vec3& getCameraPosition() const { return _cameraPosition; } diff --git a/libraries/octree/src/OctreeQueryNode.cpp b/libraries/octree/src/OctreeQueryNode.cpp index c26b4ce77b..941bb6b536 100644 --- a/libraries/octree/src/OctreeQueryNode.cpp +++ b/libraries/octree/src/OctreeQueryNode.cpp @@ -18,6 +18,12 @@ #include #include +int OctreeQueryNode::parseData(ReceivedMessage& message) { + // set our flag to indicate that we've parsed for this query at least once + _hasReceivedFirstQuery = true; + + return OctreeQuery::parseData(message); +} void OctreeQueryNode::nodeKilled() { _isShuttingDown = true; diff --git a/libraries/octree/src/OctreeQueryNode.h b/libraries/octree/src/OctreeQueryNode.h index fd89a89949..fac118c628 100644 --- a/libraries/octree/src/OctreeQueryNode.h +++ b/libraries/octree/src/OctreeQueryNode.h @@ -35,6 +35,8 @@ public: void init(); // called after creation to set up some virtual items virtual PacketType getMyPacketType() const = 0; + virtual int parseData(ReceivedMessage& message) override; + void resetOctreePacket(); // resets octree packet to after "V" header void writeToPacket(const unsigned char* buffer, unsigned int bytes); // writes to end of packet @@ -106,6 +108,8 @@ public: bool shouldForceFullScene() const { return _shouldForceFullScene; } void setShouldForceFullScene(bool shouldForceFullScene) { _shouldForceFullScene = shouldForceFullScene; } + bool hasReceivedFirstQuery() const { return _hasReceivedFirstQuery; } + private: OctreeQueryNode(const OctreeQueryNode &); OctreeQueryNode& operator= (const OctreeQueryNode&); @@ -153,6 +157,8 @@ private: QJsonObject _lastCheckJSONParameters; bool _shouldForceFullScene { false }; + + bool _hasReceivedFirstQuery { false }; }; #endif // hifi_OctreeQueryNode_h From 557ee458ecf01cbfcd44a8d3d3574e065c51bcc6 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 14 Nov 2017 17:06:46 -0800 Subject: [PATCH 2/2] wait for node active socket before constructing packets --- assignment-client/src/octree/OctreeSendThread.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/assignment-client/src/octree/OctreeSendThread.cpp b/assignment-client/src/octree/OctreeSendThread.cpp index 024071db0a..3ae653307f 100644 --- a/assignment-client/src/octree/OctreeSendThread.cpp +++ b/assignment-client/src/octree/OctreeSendThread.cpp @@ -82,9 +82,12 @@ bool OctreeSendThread::process() { if (auto node = _node.lock()) { OctreeQueryNode* nodeData = static_cast(node->getLinkedData()); - // If we don't have the OctreeQueryNode or it's uninitialized because we haven't received - // a query yet from the client then we can't send an entity data packet - if (nodeData && nodeData->hasReceivedFirstQuery() && !nodeData->isShuttingDown()) { + // If we don't have the OctreeQueryNode at all + // or it's uninitialized because we haven't received a query yet from the client + // or we don't know where we should send packets for this node + // or we're shutting down + // then we can't send an entity data packet + if (nodeData && nodeData->hasReceivedFirstQuery() && node->getActiveSocket() && !nodeData->isShuttingDown()) { bool viewFrustumChanged = nodeData->updateCurrentViewFrustum(); packetDistributor(node, nodeData, viewFrustumChanged); }