From 4b15dfd9af414ccf7a0a63a6111417ab205a182f Mon Sep 17 00:00:00 2001 From: John Senneker Date: Mon, 17 Oct 2016 18:48:04 -0400 Subject: [PATCH 1/2] Fix OBJ parser mtllib statement parsing bug. Since `getName` returns the whole line (including spaces) parse out the first word for comparison. --- code/ObjFileParser.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 9b13eea6f..7859563ee 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -182,9 +182,10 @@ void ObjFileParser::parseFile() case 'm': // Parse a material library or merging group ('mg') { - std::string name; + std::string name; - getName(m_DataIt, m_DataItEnd, name); + getName(m_DataIt, m_DataItEnd, name); + name = name.substr(0, name.find(" ")); if (name == "mg") getGroupNumberAndResolution(); else if(name == "mtllib") From acd2802f22a9cd937d3d1ec61a29e8a2b20b55ef Mon Sep 17 00:00:00 2001 From: John Senneker Date: Tue, 18 Oct 2016 10:48:47 -0400 Subject: [PATCH 2/2] Check for std::string::npos before applying std::string::substr --- code/ObjFileParser.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 7859563ee..e732eddcd 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -185,7 +185,11 @@ void ObjFileParser::parseFile() std::string name; getName(m_DataIt, m_DataItEnd, name); - name = name.substr(0, name.find(" ")); + + size_t nextSpace = name.find(" "); + if (nextSpace != std::string::npos) + name = name.substr(0, nextSpace); + if (name == "mg") getGroupNumberAndResolution(); else if(name == "mtllib")