fixed bug in writing small SVO files

This commit is contained in:
ZappoMan 2014-05-12 12:51:45 -07:00
parent 8fe74d006a
commit e4d2f07586
3 changed files with 4 additions and 8 deletions

View file

@ -263,7 +263,7 @@ int ModelItem::readModelDataFromBuffer(const unsigned char* data, int bytesLeftT
qDebug() << "readModelDataFromBuffer()... this model didn't have animation details"; qDebug() << "readModelDataFromBuffer()... this model didn't have animation details";
} }
//printf("ModelItem::readModelDataFromBuffer()... "); debugDump(); //qDebug() << "ModelItem::readModelDataFromBuffer()... "; debugDump();
} }
return bytesRead; return bytesRead;
} }
@ -417,6 +417,7 @@ void ModelItem::debugDump() const {
qDebug(" position:%f,%f,%f", _position.x, _position.y, _position.z); qDebug(" position:%f,%f,%f", _position.x, _position.y, _position.z);
qDebug(" radius:%f", getRadius()); qDebug(" radius:%f", getRadius());
qDebug(" color:%d,%d,%d", _color[0], _color[1], _color[2]); qDebug(" color:%d,%d,%d", _color[0], _color[1], _color[2]);
qDebug() << " modelURL:" << qPrintable(getModelURL());
} }
bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id, const ModelItemProperties& properties, bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id, const ModelItemProperties& properties,

View file

@ -324,7 +324,7 @@ int ModelTreeElement::readElementDataFromBuffer(const unsigned char* data, int b
dataAt += sizeof(numberOfModels); dataAt += sizeof(numberOfModels);
bytesLeftToRead -= (int)sizeof(numberOfModels); bytesLeftToRead -= (int)sizeof(numberOfModels);
bytesRead += sizeof(numberOfModels); bytesRead += sizeof(numberOfModels);
if (bytesLeftToRead >= (int)(numberOfModels * expectedBytesPerModel)) { if (bytesLeftToRead >= (int)(numberOfModels * expectedBytesPerModel)) {
for (uint16_t i = 0; i < numberOfModels; i++) { for (uint16_t i = 0; i < numberOfModels; i++) {
ModelItem tempModel; ModelItem tempModel;

View file

@ -335,10 +335,8 @@ void Octree::readBitstreamToTree(const unsigned char * bitstream, unsigned long
int octalCodeBytes = bytesRequiredForCodeLength(*bitstreamAt); int octalCodeBytes = bytesRequiredForCodeLength(*bitstreamAt);
int theseBytesRead = 0; int theseBytesRead = 0;
theseBytesRead += octalCodeBytes; theseBytesRead += octalCodeBytes;
theseBytesRead += readElementData(bitstreamRootElement, bitstreamAt + octalCodeBytes, theseBytesRead += readElementData(bitstreamRootElement, bitstreamAt + octalCodeBytes,
bufferSizeBytes - (bytesRead + octalCodeBytes), args); bufferSizeBytes - (bytesRead + octalCodeBytes), args);
// skip bitstream to new startPoint // skip bitstream to new startPoint
bitstreamAt += theseBytesRead; bitstreamAt += theseBytesRead;
bytesRead += theseBytesRead; bytesRead += theseBytesRead;
@ -1619,7 +1617,6 @@ bool Octree::readFromSVOFile(const char* fileName) {
} }
void Octree::writeToSVOFile(const char* fileName, OctreeElement* element) { void Octree::writeToSVOFile(const char* fileName, OctreeElement* element) {
std::ofstream file(fileName, std::ios::out|std::ios::binary); std::ofstream file(fileName, std::ios::out|std::ios::binary);
if(file.is_open()) { if(file.is_open()) {
@ -1642,13 +1639,12 @@ void Octree::writeToSVOFile(const char* fileName, OctreeElement* element) {
nodeBag.insert(_rootElement); nodeBag.insert(_rootElement);
} }
static OctreePacketData packetData; OctreePacketData packetData;
int bytesWritten = 0; int bytesWritten = 0;
bool lastPacketWritten = false; bool lastPacketWritten = false;
while (!nodeBag.isEmpty()) { while (!nodeBag.isEmpty()) {
OctreeElement* subTree = nodeBag.extract(); OctreeElement* subTree = nodeBag.extract();
lockForRead(); // do tree locking down here so that we have shorter slices and less thread contention lockForRead(); // do tree locking down here so that we have shorter slices and less thread contention
EncodeBitstreamParams params(INT_MAX, IGNORE_VIEW_FRUSTUM, WANT_COLOR, NO_EXISTS_BITS); EncodeBitstreamParams params(INT_MAX, IGNORE_VIEW_FRUSTUM, WANT_COLOR, NO_EXISTS_BITS);
bytesWritten = encodeTreeBitstream(subTree, &packetData, nodeBag, params); bytesWritten = encodeTreeBitstream(subTree, &packetData, nodeBag, params);
@ -1670,7 +1666,6 @@ void Octree::writeToSVOFile(const char* fileName, OctreeElement* element) {
if (!lastPacketWritten) { if (!lastPacketWritten) {
file.write((const char*)packetData.getFinalizedData(), packetData.getFinalizedSize()); file.write((const char*)packetData.getFinalizedData(), packetData.getFinalizedSize());
} }
} }
file.close(); file.close();
} }