diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index f2e65db71..6e73f0bf4 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -113,8 +113,8 @@ void ObjFileParser::parseFile() getVector3(m_pModel->m_Vertices); } else if (*m_DataIt == 't') { // read in texture coordinate ( 2D or 3D ) - ++m_DataIt; - getVector( m_pModel->m_TextureCoord ); + ++m_DataIt; + getVector( m_pModel->m_TextureCoord ); } else if (*m_DataIt == 'n') { // Read in normal vector definition ++m_DataIt; @@ -233,12 +233,13 @@ void ObjFileParser::copyNextLine(char *pBuffer, size_t length) // ------------------------------------------------------------------- void ObjFileParser::getVector( std::vector &point3d_array ) { size_t numComponents( 0 ); - DataArrayIt tmp( m_DataIt ); + const char* tmp( &m_DataIt[0] ); while( !IsLineEnd( *tmp ) ) { - if( *tmp == ' ' ) { - ++numComponents; + if ( !SkipSpaces( &tmp ) ) { + break; } - tmp++; + SkipToken( tmp ); + ++numComponents; } float x, y, z; if( 2 == numComponents ) { diff --git a/code/fast_atof.h b/code/fast_atof.h index ddda1f29e..4ff666b38 100644 --- a/code/fast_atof.h +++ b/code/fast_atof.h @@ -229,14 +229,26 @@ inline uint64_t strtoul10_64( const char* in, const char** out=0, unsigned int* template inline const char* fast_atoreal_move( const char* c, Real& out, bool check_comma = true) { - Real f; + Real f = 0; bool inv = (*c == '-'); if (inv || *c == '+') { ++c; } - f = static_cast( strtoul10_64 ( c, &c) ); + if (!(c[0] >= '0' && c[0] <= '9') && + !(c[0] == '.' && c[1] >= '0' && c[1] <= '9')) + { + throw std::invalid_argument("Cannot parse string " + "as real number: does not start with digit " + "or decimal point followed by digit."); + } + + if (*c != '.') + { + f = static_cast( strtoul10_64 ( c, &c) ); + } + if ((*c == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9') { ++c; diff --git a/test/models/OBJ/multiple_spaces.obj b/test/models/OBJ/multiple_spaces.obj new file mode 100644 index 000000000..4f27a0342 --- /dev/null +++ b/test/models/OBJ/multiple_spaces.obj @@ -0,0 +1,11 @@ +v 1.0 2.0 3.0 +v 2.0 3.0 1.0 +v 3.0 1.0 2.0 +v 1.0 2.0 3.0 + +vt 1.0 2.0 3.0 +vt 2.0 3.0 1.0 +vt 3.0 1.0 2.0 +vt 1.0 2.0 3.0 + +f 1 2 3 diff --git a/test/models/OBJ/number_formats.obj b/test/models/OBJ/number_formats.obj new file mode 100644 index 000000000..12b21bf44 --- /dev/null +++ b/test/models/OBJ/number_formats.obj @@ -0,0 +1,23 @@ +v 0 0 0 + +v 1 2. 3.0 +v +1 +2. +3.0 +v -1 -2. -3.0 + +v 1e2 2.e1 3.1e2 +v +1e2 +2.e1 +3.1e2 +v -1e2 -2.e1 -3.1e2 + +v 1e+2 2.e+1 3.1+e2 +v +1e+2 +2.e+1 +3.1+e2 +v -1e+2 -2.e+1 -3.1+e2 + +v 1e-2 2.e-1 3.1-e2 +v +1e-2 +2.e-1 +3.1-e2 +v -1e-2 -2.e-1 -3.1-e2 + +v 1e10 2.e01 3.1e10 + +v 1E2 2.E1 3.1E2 + +f 1 2 4