From f77038c52d6a75e7bccbe4f1b1aab520c21026c2 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 17 Apr 2015 09:37:48 -0700 Subject: [PATCH] when ignoring an incoming packet, still read it so the data-stream pointer doesn't get screwed up --- libraries/entities/src/EntityItem.cpp | 5 ++--- libraries/entities/src/EntityItem.h | 3 ++- libraries/entities/src/EntityTreeElement.cpp | 11 +++++------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 5a37baf4a0..3f342c4d86 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -312,7 +312,8 @@ int EntityItem::expectedBytes() { } -int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { +int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args, + bool ignoreServerPacket) { if (args.bitstreamVersion < VERSION_ENTITIES_SUPPORT_SPLIT_MTU) { @@ -421,8 +422,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef qCDebug(entities) << " fromSameServerEdit:" << fromSameServerEdit; #endif - bool ignoreServerPacket = false; // assume we'll use this server packet - // If this packet is from the same server edit as the last packet we accepted from the server // we probably want to use it. if (fromSameServerEdit) { diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 634b7e7d3d..b9def4f1db 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -113,7 +113,8 @@ public: static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args); - virtual int readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args); + virtual int readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args, + bool ignoreServerPacket = false); virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args, diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index ad268edc6f..a94891ea7e 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -696,7 +696,6 @@ bool EntityTreeElement::removeEntityItem(EntityItem* entity) { // and dirty path marking in one pass. int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { - // If we're the root, but this bitstream doesn't support root elements with data, then // return without reading any bytes if (this == _myTree->getRoot() && args.bitstreamVersion < VERSION_ROOT_ELEMENT_HAS_DATA) { @@ -735,20 +734,20 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int } // If the item already exists in our tree, we want do the following... - // 0) if this node is the simulator for the entity, ignore the update packet // 1) allow the existing item to read from the databuffer // 2) check to see if after reading the item, the containing element is still correct, fix it if needed // // TODO: Do we need to also do this? // 3) remember the old cube for the entity so we can mark it as dirty - if (entityItem && entityItem->getSimulatorID() == myNodeID) { - // do nothing, this was echoed back to us by the entity server - } else if (entityItem) { + if (entityItem) { QString entityScriptBefore = entityItem->getScript(); bool bestFitBefore = bestFitEntityBounds(entityItem); EntityTreeElement* currentContainingElement = _myTree->getContainingElement(entityItemID); - bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args); + // this Node was the original source of this packet, so read it, but ignore it. + bool shouldIgnore = (entityItem && entityItem->getSimulatorID() == myNodeID); + + bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args, shouldIgnore); if (entityItem->getDirtyFlags()) { _myTree->entityChanged(entityItem); }