Fixed loading of .obj files that do not end with a new line character.

This commit is contained in:
Ondrej Stava 2017-04-06 15:42:55 -07:00
parent 6763aa325e
commit 0d42cbb586
3 changed files with 14 additions and 2 deletions

View File

@ -369,12 +369,12 @@ bool ObjDecoder::ParseFace(bool *error) {
} else {
// Non-whitespace reached.. assume it's index declaration, skip it.
num_indices++;
while (!parser::PeekWhitespace(buffer(), &is_end)) {
while (!parser::PeekWhitespace(buffer(), &is_end) && !is_end) {
buffer()->Advance(1);
}
}
}
if (is_end || num_indices < 3 || num_indices > 4) {
if (num_indices < 3 || num_indices > 4) {
*error = true;
return false;
}

View File

@ -89,4 +89,12 @@ TEST_F(ObjDecoderTest, ComplexPolyOBJ) {
ASSERT_EQ(mesh, nullptr);
}
TEST_F(ObjDecoderTest, EOFTestOBJ) {
// Tests loading of .obj models with no new line at the end of the file.
const std::string file_name = "eof_test.obj";
const std::unique_ptr<Mesh> mesh(DecodeObj<Mesh>(file_name));
ASSERT_NE(mesh, nullptr);
ASSERT_EQ(mesh->num_faces(), 1);
}
} // namespace draco

4
testdata/eof_test.obj vendored Normal file
View File

@ -0,0 +1,4 @@
v 1.00 0.10 0.00
v 2.00 0.01 0.00
v 3.00 0.11 0.00
f 1 2 3