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();
}