diff --git a/src/coders/obj.cpp b/src/coders/obj.cpp index 0eed9bf6..d7ff244a 100644 --- a/src/coders/obj.cpp +++ b/src/coders/obj.cpp @@ -10,20 +10,21 @@ class ObjParser : BasicParser { std::vector uvs {{0, 0}}; std::vector normals {{0, 1, 0}}; + // TODO: refactor void parseFace(Mesh& mesh) { std::vector vertices; while (hasNext()) { auto c = peekInLine(); if (c == '\n') { break; - } else { + } else if (hasNext()) { uint indices[3] {}; uint i = 0; do { char next = peekInLine(); if (is_digit(next)) { indices[i] = parseSimpleInt(10); - if (peekInLine() == '/') { + if (hasNext() && peekInLine() == '/') { pos++; } } else if (next == '/') { @@ -31,13 +32,13 @@ class ObjParser : BasicParser { } else { break; } - } while (peekInLine() != '\n' && ++i < 3); + } while (hasNext() && peekInLine() != '\n' && ++i < 3); vertices.push_back(Vertex { coords[indices[0]], uvs[indices[1]], normals[indices[2]]}); } } - if (peekInLine() != '\n' && hasNext()) { + if (hasNext() && peekInLine() != '\n') { skipLine(); } if (vertices.size() >= 3) {