ObjLoader Debugging
The OBJ loader you are given loads a valid file, but but fails to provide feedback if the file format is incorrect
Assignment: make every format error explain itself and extend its capability.
1. Quick Start
Download cpp projectcmake -S . -B build && cmake --build build
./build/objloader_tests
You should see 3 of 11 passing, and the run ends in a crash at case 10, missing_uv_data.
All of this is expected.
Two ways to run it:
./build/objloader_tests # run everything
./build/objloader_tests --only test05_face_not_triangle.obj # one case with full detail
--only <value> takes the exact .obj filename of one of the built-in cases.
2. Files
You should only edit src/objloader.cpp.
| Path | Content |
|---|---|
src/objloader.cpp | starter code |
include/objloader.hpp | API and ObjIssue list |
src/diagnostics.cpp | message formatting and report printing |
tests/test_objloader.cpp | test runner |
tests/models/test01_... - test11_... | test files (see table below) |
external/glm/ | glm headers |
3. The 10 Cases
include/objloader.hpp defines 10 ObjIssue this loader can detect.
There are 11 test cases - one per condition, plus one baseline case (strict).
- Every one of the 10 can be recognized, named correctly, and rejected cleanly.
- Some of them can also be handled gracefully instead of rejected.
4. Test Files
4.1. Description
| # | File | Test case | Issue | Outcome required |
|---|---|---|---|---|
| 01 | test01_strict.obj | strict | (none - baseline) | loads cleanly with 0 diagnostics |
| 02 | test02_malformed_vertex.obj | malformed_vertex | MalformedVertex | reject |
| 03 | test03_malformed_texcoord.obj | malformed_texcoord | MalformedTexCoord | reject |
| 04 | test04_malformed_normal.obj | malformed_normal | MalformedNormal | reject |
| 05 | test05_face_not_triangle.obj | face_not_triangle | FaceNotTriangle | reject |
| 06 | test06_malformed_face_vertex.obj | malformed_face_vertex | MalformedFaceVertex | reject |
| 07 | *(no file - path doesn't exist)* | file_not_found | FileNotFound | reject |
| 08 | test08_missing_normal_data.obj | missing_normal_data | MissingNormalData | accept, with warning |
| 09 | test09_index_out_of_range.obj | index_out_of_range | IndexOutOfRange | reject |
| 10 | test10_missing_uv_data.obj | missing_uv_data | MissingUVData | accept, with warning |
| 11 | test11_negative_index_unsupported.obj | negative_index_unsupported | NegativeIndexUnsupported | reject |
4.2 Hints
| File | What's inside |
|---|---|
test01_strict.obj | Unit square in the XZ plane, two triangles, facing +Y, full v/vt/vn form. |
test02_malformed_vertex.obj | A v line with only 2 numbers instead of 3, referenced by a face. |
test03_malformed_texcoord.obj | A vt line with only 1 number instead of 2, referenced by a face (v/vt form). |
test04_malformed_normal.obj | A vn line with only 2 numbers instead of 3, referenced by a face (v//vn form). |
test05_face_not_triangle.obj | A square as one 4-vertex face instead of two triangles. |
test06_malformed_face_vertex.obj | A face token with four slash-separated fields. |
test08_missing_normal_data.obj | Bare position-only faces with no normal referenced. |
test09_index_out_of_range.obj | The face cites position 99 in a file that only defines 4 positions. |
test10_missing_uv_data.obj | A face references a uv slot, but the file defines zero vt lines anywhere. |
test11_negative_index_unsupported.obj | Every face-vertex index is negative. Valid OBJ meaning "counted backward from the most recently defined element," is not implemented here. |
The suite checks the ObjIssue value, never your message wording, so phrase detail however you like.