diff --git a/assignment-client/src/avatars/AvatarMixer.cpp b/assignment-client/src/avatars/AvatarMixer.cpp index 0135e62143..0d4e5b5934 100644 --- a/assignment-client/src/avatars/AvatarMixer.cpp +++ b/assignment-client/src/avatars/AvatarMixer.cpp @@ -408,7 +408,6 @@ void AvatarMixer::readPendingDatagrams() { break; } case PacketType::AvatarIdentity: { - // check if we have a matching node in our list SharedNodePointer avatarNode = nodeList->sendingNodeForPacket(receivedPacket); @@ -425,7 +424,6 @@ void AvatarMixer::readPendingDatagrams() { break; } case PacketType::AvatarBillboard: { - // check if we have a matching node in our list SharedNodePointer avatarNode = nodeList->sendingNodeForPacket(receivedPacket); diff --git a/assignment-client/src/octree/OctreeQueryNode.h b/assignment-client/src/octree/OctreeQueryNode.h index 5964d4eaf1..6316cc5e86 100644 --- a/assignment-client/src/octree/OctreeQueryNode.h +++ b/assignment-client/src/octree/OctreeQueryNode.h @@ -14,7 +14,6 @@ #include - #include #include #include @@ -104,7 +103,7 @@ public: void forceNodeShutdown(); bool isShuttingDown() const { return _isShuttingDown; } - void octreePacketSent() { packetSent(*_octreePacket.get()); } + void octreePacketSent() { packetSent(*_octreePacket); } void packetSent(const NLPacket& packet); OCTREE_PACKET_SEQUENCE getSequenceNumber() const { return _sequenceNumber; } diff --git a/libraries/networking/src/NLPacket.cpp b/libraries/networking/src/NLPacket.cpp index 4f17d3d754..1b1ac50eda 100644 --- a/libraries/networking/src/NLPacket.cpp +++ b/libraries/networking/src/NLPacket.cpp @@ -11,13 +11,13 @@ #include "NLPacket.h" -int64_t NLPacket::localHeaderSize(PacketType::Value type) { - int64_t size = ((NON_SOURCED_PACKETS.contains(type)) ? 0 : NUM_BYTES_RFC4122_UUID) + +qint64 NLPacket::localHeaderSize(PacketType::Value type) { + qint64 size = ((NON_SOURCED_PACKETS.contains(type)) ? 0 : NUM_BYTES_RFC4122_UUID) + ((NON_VERIFIED_PACKETS.contains(type)) ? 0 : NUM_BYTES_RFC4122_UUID); return size; } -int64_t NLPacket::maxPayloadSize(PacketType::Value type) { +qint64 NLPacket::maxPayloadSize(PacketType::Value type) { return Packet::maxPayloadSize(type) - localHeaderSize(type); } @@ -29,11 +29,17 @@ qint64 NLPacket::localHeaderSize() const { return localHeaderSize(_type); } -std::unique_ptr NLPacket::create(PacketType::Value type, int64_t size) { - if (size > maxPayloadSize(type)) { - return std::unique_ptr(); +std::unique_ptr NLPacket::create(PacketType::Value type, qint64 size) { + auto maxPayload = maxPayloadSize(type); + if (size == -1) { + // default size of -1, means biggest packet possible + size = maxPayload; } - + + // Fail with invalid size + Q_ASSERT(size >= 0 || size < maxPayload); + + // allocate memory return std::unique_ptr(new NLPacket(type, size)); } @@ -41,7 +47,7 @@ std::unique_ptr NLPacket::createCopy(const NLPacket& other) { return std::unique_ptr(new NLPacket(other)); } -NLPacket::NLPacket(PacketType::Value type, int64_t size) : Packet(type, localHeaderSize(type) + size) { +NLPacket::NLPacket(PacketType::Value type, qint64 size) : Packet(type, localHeaderSize(type) + size) { } NLPacket::NLPacket(const NLPacket& other) : Packet(other) { diff --git a/libraries/networking/src/NLPacket.h b/libraries/networking/src/NLPacket.h index 9368b25720..e70df1dad7 100644 --- a/libraries/networking/src/NLPacket.h +++ b/libraries/networking/src/NLPacket.h @@ -17,18 +17,18 @@ class NLPacket : public Packet { Q_OBJECT public: - static std::unique_ptr create(PacketType::Value type, int64_t size = -1); + static std::unique_ptr create(PacketType::Value type, qint64 size = -1); // Provided for convenience, try to limit use static std::unique_ptr createCopy(const NLPacket& other); - static int64_t localHeaderSize(PacketType::Value type); - static int64_t maxPayloadSize(PacketType::Value type); + static qint64 localHeaderSize(PacketType::Value type); + static qint64 maxPayloadSize(PacketType::Value type); virtual qint64 totalHeadersSize() const; // Cumulated size of all the headers virtual qint64 localHeaderSize() const; // Current level's header size protected: - NLPacket(PacketType::Value type, int64_t size); + NLPacket(PacketType::Value type, qint64 size); NLPacket(const NLPacket& other); void setSourceUuid(QUuid sourceUuid); diff --git a/libraries/networking/src/Packet.cpp b/libraries/networking/src/Packet.cpp index 6d585ac4aa..876cd91962 100644 --- a/libraries/networking/src/Packet.cpp +++ b/libraries/networking/src/Packet.cpp @@ -29,10 +29,9 @@ std::unique_ptr Packet::create(PacketType::Value type, qint64 size) { // default size of -1, means biggest packet possible size = maxPayload; } - if (size <= 0 || size > maxPayload) { - // Invalid size, return null pointer - return std::unique_ptr(); - } + + // Fail with invalid size + Q_ASSERT(size >= 0 || size < maxPayload); // allocate memory return std::unique_ptr(new Packet(type, size)); diff --git a/libraries/networking/src/Packet.h b/libraries/networking/src/Packet.h index 1de17602da..e9483ca1f1 100644 --- a/libraries/networking/src/Packet.h +++ b/libraries/networking/src/Packet.h @@ -23,7 +23,7 @@ class Packet : public QIODevice { public: using SequenceNumber = uint16_t; - static std::unique_ptr create(PacketType::Value type, int64_t size = -1); + static std::unique_ptr create(PacketType::Value type, qint64 size = -1); // Provided for convenience, try to limit use static std::unique_ptr createCopy(const Packet& other); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 1a9088ca4b..f388785f1e 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -675,7 +675,7 @@ void ScriptEngine::run() { audioPacket->writePrimitive(sequence); // send audio packet - nodeList->sendUnreliablePacket(audioPacket, node); + nodeList->sendUnreliablePacket(*audioPacket, node); } }); } diff --git a/libraries/shared/src/RingBufferHistory.h b/libraries/shared/src/RingBufferHistory.h index 6408373079..c0bd1e2a6e 100644 --- a/libraries/shared/src/RingBufferHistory.h +++ b/libraries/shared/src/RingBufferHistory.h @@ -45,7 +45,7 @@ public: void insert(const T& entry) { // increment newest entry index cyclically - _newestEntryAtIndex = (_newestEntryAtIndex + 1) % size; + _newestEntryAtIndex = (_newestEntryAtIndex + 1) % _size; // insert new entry _buffer[_newestEntryAtIndex] = entry; @@ -57,7 +57,7 @@ public: // std::unique_ptr need to be passed as an rvalue ref and moved into the vector void insert(T&& entry) { // increment newest entry index cyclically - _newestEntryAtIndex = (_newestEntryAtIndex == _size - 1) ? 0 : _newestEntryAtIndex + 1; + _newestEntryAtIndex = (_newestEntryAtIndex + 1) % _size; // insert new entry _buffer[_newestEntryAtIndex] = std::move(entry);