From ef1ee63f03c5b79ccc267533bac77d5a49c478a1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 11 Jul 2008 17:46:30 +0000 Subject: [PATCH] From Joakim Simmonson, "Opcodes.h: * Added INVALID_OP as -1 in the Opcodes enum. Note that INVALID_OP is not an actual opcode defined in the OpenFlight format. The purpose of INVALID_OP is to mark an opcode variable as invalid or uninitialized. ReaderWriterFLT.cpp: * The header node is returned if it exists, even if the file does not contain a node hierarchy. The old behaviour returned a ERROR_IN_READING_FILE error. * Changed opcodes initialized to -1 to the new enum value INVALID_OP." --- src/osgPlugins/OpenFlight/Opcodes.h | 4 ++++ src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp | 21 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/osgPlugins/OpenFlight/Opcodes.h b/src/osgPlugins/OpenFlight/Opcodes.h index 510e69814..8304341d3 100644 --- a/src/osgPlugins/OpenFlight/Opcodes.h +++ b/src/osgPlugins/OpenFlight/Opcodes.h @@ -22,8 +22,12 @@ namespace flt { + +// Note that INVALID_OP = -1 is not an actual opcode defined in the OpenFlight format. +// The purpose of INVALID_OP is to mark an opcode variable as invalid or uninitialized. enum Opcodes { + INVALID_OP = -1, UNKNOWN_OP = 0, HEADER_OP = 1, GROUP_OP = 2, diff --git a/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp b/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp index e01235882..01372fed1 100644 --- a/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp +++ b/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp @@ -86,7 +86,7 @@ public: /*! -FLTReaderWriter supports importing and exporting OSG scene grqphs +FLTReaderWriter supports importing and exporting OSG scene graphs from/to OpenFlight files. @@ -284,7 +284,7 @@ class FLTReaderWriter : public ReaderWriter } const int RECORD_HEADER_SIZE = 4; - opcode_type continuationOpcode = -1; + opcode_type continuationOpcode = INVALID_OP; std::string continuationBuffer; while (fin.good() && !document.done()) @@ -299,8 +299,21 @@ class FLTReaderWriter : public ReaderWriter opcode_type opcode = (opcode_type)dataStream.readUInt16(); size_type size = (size_type)dataStream.readUInt16(); + // If size == 0, an EOF has probably been reached, i.e. there is nothing + // more to read so we must return. if (size==0) - return ReadResult::ERROR_IN_READING_FILE; + { + // If a header was read, we return it. + // This allows us handle files with empty hierarchies. + if (document.getHeaderNode()) + { + return document.getHeaderNode(); + } + else // (no valid header) + { + return ReadResult::ERROR_IN_READING_FILE; + } + } // variable length record complete? if (!continuationBuffer.empty() && opcode!=CONTINUATION_OP) @@ -310,7 +323,7 @@ class FLTReaderWriter : public ReaderWriter flt::RecordInputStream recordStream(&sb); recordStream.readRecordBody(continuationOpcode, continuationBuffer.length(), document); - continuationOpcode = -1; + continuationOpcode = INVALID_OP; continuationBuffer.clear(); }