Correction of a bug in the OBJ parser

cyril
2012-07-10
2013-06-03
  • cyril
    cyril
    2012-07-10

    Hello,

    I encountered a bug when loading a mtl file:
    if a line is "map_bump "
    (without texture name),
    an exception is thrown.

    adding these lines

      // if there is no name, and the previous char is a separator, come back to start
      while (&(*it) < pStart) {
        ++it;
      }

    before
    // Get name
    std::string strName( pStart, &(*it) );

    in the ObjTools.h, in the function
    template<class char_t>
    inline char_t getName( char_t it, char_t end, std::string &name )

    avoid the crash (but i do not know if it correctly take the map_bump into account).

     
  • cyril
    cyril
    2012-07-10

    I corrected another crash, but again, I do not know if it's the correct behavior, since I know nothing about 3D models.
    In ObjFileImporter.cpp, function createVertexArray:
    I added the verification of index validity on source face normals and texture coords

    // Copy all normals
    if ( !pSourceFace->m_pNormals->empty() &&
              !pSourceFace->m_pNormals->size() > vertexIndex &&
              !pModel->m_Normals.empty())
    {
                               …
    }

    // Copy all texture coordinates
    if ( !pModel->m_TextureCoord.empty())
    {
    if ( !pSourceFace->m_pTexturCoords->empty() &&
                !pSourceFace->m_pTexturCoords->size() > vertexIndex)
    {

    }
    }

     
  • cyril
    cyril
    2012-07-10

    sorry, problem:

    pSourceFace->m_pNormals->size() > vertexIndex &&
    and
    pSourceFace->m_pTexturCoords->size() > vertexIndex

    (without the !)

     
  • Kim Kulling
    Kim Kulling
    2012-07-11

    Hi,

    thanks a lot for that fixes. I will test and deliver them, if tey are ok ( as it seems :-) ) !

    Kimmi

     
  • cyril
    cyril
    2012-07-11

    Hello Kimmi,
    we intend to use assimp extensively,
    We include assimp as a c++ library in iOs and Android applications.
    We will probably add other bug corrections (like the iOs compilation script that do not work on mac os x lion),
    would you like a more close relation with us ?
    Regards,
    Cyril

     
  • Kim Kulling
    Kim Kulling
    2012-07-11

    Sure, sounds good to me :-). You can use my sourceforge adress to contact me.

    Kimmi

     
  • You might also want to consider submitting your fixes as patches (in unified diff format, the norm with virtually all open source projects), because it makes it easier for developers to review and apply the changes.

     
  • Kim Kulling
    Kim Kulling
    2012-07-17

    About the last patch: Ia m not sure if std::vector<t>::at will check this and throw an exception. That is the reason for use this method.

    Kimmi