Merged
Conversation
In the OBJ file if the first line starts with a invisible BOM char like:\uFEFFmtllib model.mtl the parsing of the textures does not work.
There was a problem hiding this comment.
Pull Request Overview
Adds handling for UTF-8 BOM characters at the start of OBJ/MTL files to ensure correct parsing of mtllib and other tokens.
- Introduce
removeUtf8Bomhelper to strip BOM bytes if present. - Invoke BOM removal on each line before token parsing in
LoadMtlandLoadObj.
Comments suppressed due to low confidence (1)
tiny_obj_loader.h:2124
- The new BOM-removal behavior isn't covered by existing tests. Add unit tests for lines starting with
\uFEFFto ensure this function works as expected.
linebuf = removeUtf8Bom(linebuf);
Collaborator
|
Please add reproducible test .obj/.mtl to |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Add if (line_no == 1) removeUtf8Bom(linebuf) to obj aswell
Contributor
Author
|
@syoyo I added a unit test for removeUtf8Bom and a test with UTF-8 BOM encoded models. As Copilot suggested I also added the BOM check to the MTL file not only the obj file. Let me know if there are any further changes you want me to make. |
Collaborator
|
@paulbauriegel Thank you! Will be merged soon after the review. |
Collaborator
|
Merged! Thanks! |
syoyo
pushed a commit
that referenced
this pull request
Nov 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the OBJ file if the first line starts with a invisible BOM char like: \uFEFFmtllib model.mtl
The parsing of the textures does not work in that case because of
if ((0 == strncmp(token, "mtllib", 6)) && IS_SPACE((token[6]))) {