Skip to content

Commit

Permalink
Merge pull request #103 from marchelbling/update_stl
Browse files Browse the repository at this point in the history
Update stl.

    fixes magics color parsing
    adds support for incomplete binary stl files
  • Loading branch information
OpenSceneGraph git repository committed Jul 5, 2016
2 parents ca43559 + e4c31cd commit bb50987
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/osgPlugins/stl/ReaderWriterSTL.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bb50987

Please sign in to comment.