From f4d0131967b0a72a880a79a017743b572a16d141 Mon Sep 17 00:00:00 2001 From: Marc Helbling Date: Tue, 5 Jul 2016 17:01:42 +0200 Subject: [PATCH 1/2] Fixes magics color parsing `fread` returns the number of objects read, not a byte-size. --- src/osgPlugins/stl/ReaderWriterSTL.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/osgPlugins/stl/ReaderWriterSTL.cpp b/src/osgPlugins/stl/ReaderWriterSTL.cpp index 1a1eb0352..2bc72a837 100644 --- a/src/osgPlugins/stl/ReaderWriterSTL.cpp +++ b/src/osgPlugins/stl/ReaderWriterSTL.cpp @@ -405,8 +405,8 @@ bool fileComesFromMagics(FILE *fp, osg::Vec4& magicsColor) ::rewind(fp); - size_t bytes_read = fread((void*) &header, sizeof(header), 1, fp); - if (bytes_read!=sizeof(header)) return false; + if (fread((void*) &header, sizeof(header), 1, fp) != 1) + return false; if (::fseek(fp, sizeof_StlHeader, SEEK_SET)!=0) { From e4c31cdcbfd8670cd6bd4bb04f0ffc40eee07d36 Mon Sep 17 00:00:00 2001 From: Marc Helbling Date: Tue, 5 Jul 2016 17:08:08 +0200 Subject: [PATCH 2/2] Adds support for incomplete stl binary files The logic is * if a file is not ascii * if its sizeis less than the expected binary size then we can assume that the data is incomplete but still try to load it. --- src/osgPlugins/stl/ReaderWriterSTL.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/osgPlugins/stl/ReaderWriterSTL.cpp b/src/osgPlugins/stl/ReaderWriterSTL.cpp index 2bc72a837..89556149b 100644 --- a/src/osgPlugins/stl/ReaderWriterSTL.cpp +++ b/src/osgPlugins/stl/ReaderWriterSTL.cpp @@ -481,8 +481,16 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil std::string header_text(header.text, sizeof(header.text)); - if (stb.st_size == expectLen) + if (header_text.find("solid") == std::string::npos || stb.st_size == expectLen) { + if(stb.st_size < expectLen) + { + unsigned int facets = (stb.st_size - sizeof_StlHeader) / sizeof_StlFacet; + OSG_WARN << "Warning: [[stl]] Incomplete file. " + << "Attempting to read " << facets << " out of " << expectFacets << " facets expected." + << std::endl; + expectFacets = facets; + } isBinary = true; } else if (header_text.find("solid") != std::string::npos)