mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 19:10:56 +02:00
Merge pull request #1873 from ZappoMan/bugfixes
Fix corruption in voxel packets
This commit is contained in:
commit
c194ad1b2d
6 changed files with 28 additions and 39 deletions
|
@ -73,12 +73,12 @@ void DatagramProcessor::processDatagrams() {
|
||||||
if (wantExtraDebugging && packetTypeForPacket(incomingPacket) == PacketTypeVoxelData) {
|
if (wantExtraDebugging && packetTypeForPacket(incomingPacket) == PacketTypeVoxelData) {
|
||||||
int numBytesPacketHeader = numBytesForPacketHeader(incomingPacket);
|
int numBytesPacketHeader = numBytesForPacketHeader(incomingPacket);
|
||||||
unsigned char* dataAt = reinterpret_cast<unsigned char*>(incomingPacket.data()) + numBytesPacketHeader;
|
unsigned char* dataAt = reinterpret_cast<unsigned char*>(incomingPacket.data()) + numBytesPacketHeader;
|
||||||
dataAt += sizeof(VOXEL_PACKET_FLAGS);
|
dataAt += sizeof(OCTREE_PACKET_FLAGS);
|
||||||
VOXEL_PACKET_SEQUENCE sequence = (*(VOXEL_PACKET_SEQUENCE*)dataAt);
|
OCTREE_PACKET_SEQUENCE sequence = (*(OCTREE_PACKET_SEQUENCE*)dataAt);
|
||||||
dataAt += sizeof(VOXEL_PACKET_SEQUENCE);
|
dataAt += sizeof(OCTREE_PACKET_SEQUENCE);
|
||||||
VOXEL_PACKET_SENT_TIME sentAt = (*(VOXEL_PACKET_SENT_TIME*)dataAt);
|
OCTREE_PACKET_SENT_TIME sentAt = (*(OCTREE_PACKET_SENT_TIME*)dataAt);
|
||||||
dataAt += sizeof(VOXEL_PACKET_SENT_TIME);
|
dataAt += sizeof(OCTREE_PACKET_SENT_TIME);
|
||||||
VOXEL_PACKET_SENT_TIME arrivedAt = usecTimestampNow();
|
OCTREE_PACKET_SENT_TIME arrivedAt = usecTimestampNow();
|
||||||
int flightTime = arrivedAt - sentAt;
|
int flightTime = arrivedAt - sentAt;
|
||||||
|
|
||||||
printf("got PacketType_VOXEL_DATA, sequence:%d flightTime:%d\n", sequence, flightTime);
|
printf("got PacketType_VOXEL_DATA, sequence:%d flightTime:%d\n", sequence, flightTime);
|
||||||
|
|
|
@ -561,30 +561,30 @@ int VoxelSystem::parseData(const QByteArray& packet) {
|
||||||
|
|
||||||
const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data()) + numBytesPacketHeader;
|
const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data()) + numBytesPacketHeader;
|
||||||
|
|
||||||
VOXEL_PACKET_FLAGS flags = (*(VOXEL_PACKET_FLAGS*)(dataAt));
|
OCTREE_PACKET_FLAGS flags = (*(OCTREE_PACKET_FLAGS*)(dataAt));
|
||||||
dataAt += sizeof(VOXEL_PACKET_FLAGS);
|
dataAt += sizeof(OCTREE_PACKET_FLAGS);
|
||||||
VOXEL_PACKET_SEQUENCE sequence = (*(VOXEL_PACKET_SEQUENCE*)dataAt);
|
OCTREE_PACKET_SEQUENCE sequence = (*(OCTREE_PACKET_SEQUENCE*)dataAt);
|
||||||
dataAt += sizeof(VOXEL_PACKET_SEQUENCE);
|
dataAt += sizeof(OCTREE_PACKET_SEQUENCE);
|
||||||
|
|
||||||
VOXEL_PACKET_SENT_TIME sentAt = (*(VOXEL_PACKET_SENT_TIME*)dataAt);
|
OCTREE_PACKET_SENT_TIME sentAt = (*(OCTREE_PACKET_SENT_TIME*)dataAt);
|
||||||
dataAt += sizeof(VOXEL_PACKET_SENT_TIME);
|
dataAt += sizeof(OCTREE_PACKET_SENT_TIME);
|
||||||
|
|
||||||
bool packetIsColored = oneAtBit(flags, PACKET_IS_COLOR_BIT);
|
bool packetIsColored = oneAtBit(flags, PACKET_IS_COLOR_BIT);
|
||||||
bool packetIsCompressed = oneAtBit(flags, PACKET_IS_COMPRESSED_BIT);
|
bool packetIsCompressed = oneAtBit(flags, PACKET_IS_COMPRESSED_BIT);
|
||||||
|
|
||||||
VOXEL_PACKET_SENT_TIME arrivedAt = usecTimestampNow();
|
OCTREE_PACKET_SENT_TIME arrivedAt = usecTimestampNow();
|
||||||
int flightTime = arrivedAt - sentAt;
|
int flightTime = arrivedAt - sentAt;
|
||||||
|
|
||||||
VOXEL_PACKET_INTERNAL_SECTION_SIZE sectionLength = 0;
|
OCTREE_PACKET_INTERNAL_SECTION_SIZE sectionLength = 0;
|
||||||
int dataBytes = packet.size() - VOXEL_PACKET_HEADER_SIZE;
|
int dataBytes = packet.size() - (numBytesPacketHeader + OCTREE_PACKET_EXTRA_HEADERS_SIZE);
|
||||||
|
|
||||||
int subsection = 1;
|
int subsection = 1;
|
||||||
while (dataBytes > 0) {
|
while (dataBytes > 0) {
|
||||||
if (packetIsCompressed) {
|
if (packetIsCompressed) {
|
||||||
if (dataBytes > sizeof(VOXEL_PACKET_INTERNAL_SECTION_SIZE)) {
|
if (dataBytes > sizeof(OCTREE_PACKET_INTERNAL_SECTION_SIZE)) {
|
||||||
sectionLength = (*(VOXEL_PACKET_INTERNAL_SECTION_SIZE*)dataAt);
|
sectionLength = (*(OCTREE_PACKET_INTERNAL_SECTION_SIZE*)dataAt);
|
||||||
dataAt += sizeof(VOXEL_PACKET_INTERNAL_SECTION_SIZE);
|
dataAt += sizeof(OCTREE_PACKET_INTERNAL_SECTION_SIZE);
|
||||||
dataBytes -= sizeof(VOXEL_PACKET_INTERNAL_SECTION_SIZE);
|
dataBytes -= sizeof(OCTREE_PACKET_INTERNAL_SECTION_SIZE);
|
||||||
} else {
|
} else {
|
||||||
sectionLength = 0;
|
sectionLength = 0;
|
||||||
dataBytes = 0; // stop looping something is wrong
|
dataBytes = 0; // stop looping something is wrong
|
||||||
|
|
|
@ -46,9 +46,12 @@ void OctreeQueryNode::initializeOctreeSendThread(OctreeServer* octreeServer, con
|
||||||
bool OctreeQueryNode::packetIsDuplicate() const {
|
bool OctreeQueryNode::packetIsDuplicate() const {
|
||||||
// since our packets now include header information, like sequence number, and createTime, we can't just do a memcmp
|
// since our packets now include header information, like sequence number, and createTime, we can't just do a memcmp
|
||||||
// of the entire packet, we need to compare only the packet content...
|
// of the entire packet, we need to compare only the packet content...
|
||||||
|
int numBytesPacketHeader = numBytesForPacketHeaderGivenPacketType(getMyPacketType());
|
||||||
|
|
||||||
if (_lastOctreePacketLength == getPacketLength()) {
|
if (_lastOctreePacketLength == getPacketLength()) {
|
||||||
if (memcmp(_lastOctreePacket + OCTREE_PACKET_HEADER_SIZE,
|
if (memcmp(_lastOctreePacket + (numBytesPacketHeader + OCTREE_PACKET_EXTRA_HEADERS_SIZE),
|
||||||
_octreePacket + OCTREE_PACKET_HEADER_SIZE , getPacketLength() - OCTREE_PACKET_HEADER_SIZE) == 0) {
|
_octreePacket + (numBytesPacketHeader + OCTREE_PACKET_EXTRA_HEADERS_SIZE),
|
||||||
|
getPacketLength() - (numBytesPacketHeader + OCTREE_PACKET_EXTRA_HEADERS_SIZE)) == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,7 +128,7 @@ void OctreeQueryNode::resetOctreePacket(bool lastWasSurpressed) {
|
||||||
*sequenceAt = _sequenceNumber;
|
*sequenceAt = _sequenceNumber;
|
||||||
_octreePacketAt += sizeof(OCTREE_PACKET_SEQUENCE);
|
_octreePacketAt += sizeof(OCTREE_PACKET_SEQUENCE);
|
||||||
_octreePacketAvailableBytes -= sizeof(OCTREE_PACKET_SEQUENCE);
|
_octreePacketAvailableBytes -= sizeof(OCTREE_PACKET_SEQUENCE);
|
||||||
if (!(lastWasSurpressed || _lastOctreePacketLength == OCTREE_PACKET_HEADER_SIZE)) {
|
if (!(lastWasSurpressed || _lastOctreePacketLength == (numBytesPacketHeader + OCTREE_PACKET_EXTRA_HEADERS_SIZE))) {
|
||||||
_sequenceNumber++;
|
_sequenceNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,10 @@ typedef uint16_t OCTREE_PACKET_INTERNAL_SECTION_SIZE;
|
||||||
const int MAX_OCTREE_PACKET_SIZE = MAX_PACKET_SIZE;
|
const int MAX_OCTREE_PACKET_SIZE = MAX_PACKET_SIZE;
|
||||||
|
|
||||||
// this is overly conservative - sizeof(PacketType) is 8 bytes but a packed PacketType could be as small as one byte
|
// this is overly conservative - sizeof(PacketType) is 8 bytes but a packed PacketType could be as small as one byte
|
||||||
const int OCTREE_PACKET_HEADER_SIZE = MAX_PACKET_HEADER_BYTES + sizeof(OCTREE_PACKET_FLAGS)
|
const int OCTREE_PACKET_EXTRA_HEADERS_SIZE = sizeof(OCTREE_PACKET_FLAGS)
|
||||||
+ sizeof(OCTREE_PACKET_SEQUENCE) + sizeof(OCTREE_PACKET_SENT_TIME);
|
+ sizeof(OCTREE_PACKET_SEQUENCE) + sizeof(OCTREE_PACKET_SENT_TIME);
|
||||||
|
|
||||||
const int MAX_OCTREE_PACKET_DATA_SIZE = MAX_PACKET_SIZE - OCTREE_PACKET_HEADER_SIZE;
|
const int MAX_OCTREE_PACKET_DATA_SIZE = MAX_PACKET_SIZE - (MAX_PACKET_HEADER_BYTES + OCTREE_PACKET_EXTRA_HEADERS_SIZE);
|
||||||
|
|
||||||
const int MAX_OCTREE_UNCOMRESSED_PACKET_SIZE = MAX_OCTREE_PACKET_DATA_SIZE;
|
const int MAX_OCTREE_UNCOMRESSED_PACKET_SIZE = MAX_OCTREE_PACKET_DATA_SIZE;
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ void OctreeRenderer::processDatagram(const QByteArray& dataByteArray, const Hifi
|
||||||
int flightTime = arrivedAt - sentAt + clockSkew;
|
int flightTime = arrivedAt - sentAt + clockSkew;
|
||||||
|
|
||||||
OCTREE_PACKET_INTERNAL_SECTION_SIZE sectionLength = 0;
|
OCTREE_PACKET_INTERNAL_SECTION_SIZE sectionLength = 0;
|
||||||
int dataBytes = packetLength - OCTREE_PACKET_HEADER_SIZE;
|
int dataBytes = packetLength - (numBytesPacketHeader + OCTREE_PACKET_EXTRA_HEADERS_SIZE);
|
||||||
|
|
||||||
if (extraDebugging) {
|
if (extraDebugging) {
|
||||||
qDebug("OctreeRenderer::processDatagram() ... Got Packet Section"
|
qDebug("OctreeRenderer::processDatagram() ... Got Packet Section"
|
||||||
|
|
|
@ -26,20 +26,6 @@
|
||||||
#include "VoxelConstants.h"
|
#include "VoxelConstants.h"
|
||||||
#include "VoxelTreeElement.h"
|
#include "VoxelTreeElement.h"
|
||||||
|
|
||||||
typedef unsigned char VOXEL_PACKET_FLAGS;
|
|
||||||
typedef uint16_t VOXEL_PACKET_SEQUENCE;
|
|
||||||
typedef quint64 VOXEL_PACKET_SENT_TIME;
|
|
||||||
typedef uint16_t VOXEL_PACKET_INTERNAL_SECTION_SIZE;
|
|
||||||
const int MAX_VOXEL_PACKET_SIZE = MAX_PACKET_SIZE;
|
|
||||||
|
|
||||||
// this is overly conservative - uses 8 bytes for PacketType which could be as compact as a single byte
|
|
||||||
const int VOXEL_PACKET_HEADER_SIZE = MAX_PACKET_HEADER_BYTES + sizeof(VOXEL_PACKET_FLAGS)
|
|
||||||
+ sizeof(VOXEL_PACKET_SEQUENCE) + sizeof(VOXEL_PACKET_SENT_TIME);
|
|
||||||
|
|
||||||
const int MAX_VOXEL_PACKET_DATA_SIZE = MAX_PACKET_SIZE - VOXEL_PACKET_HEADER_SIZE;
|
|
||||||
|
|
||||||
const int MAX_VOXEL_UNCOMRESSED_PACKET_SIZE = MAX_VOXEL_PACKET_DATA_SIZE;
|
|
||||||
|
|
||||||
/// Handles packing of the data portion of PacketType_VOXEL_DATA messages.
|
/// Handles packing of the data portion of PacketType_VOXEL_DATA messages.
|
||||||
class VoxelPacketData : public OctreePacketData {
|
class VoxelPacketData : public OctreePacketData {
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue