Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File format fix #160

Merged
merged 5 commits into from
Apr 7, 2021
Merged

File format fix #160

merged 5 commits into from
Apr 7, 2021

Conversation

JonathanB-Vobling
Copy link
Contributor

If a GLTF had URL query strings as part of its image URLs it GLTFast.cs would not recognize the file format. This was causing problems for me since I was getting GLTFs from a CDN that auto-generated the GLTFs with things like texture version info in the query strings. I fixed this by adding a set of "contains" checks after the "ends with" checks in GLTFast.cs. I added them at the end so that they will only be used if it does not end with a file format since I suspect that this will still be far more common.

…tely and after the ends with comparison since ends with is probably more common.
Runtime/Scripts/GltFast.cs Show resolved Hide resolved
Runtime/Scripts/GltFast.cs Show resolved Hide resolved
|| path.EndsWith(".jpeg",StringComparison.OrdinalIgnoreCase)) return ImageFormat.Jpeg;
if(path.EndsWith(".ktx",StringComparison.OrdinalIgnoreCase)
|| path.EndsWith(".ktx2",StringComparison.OrdinalIgnoreCase)) return ImageFormat.KTX;
if(path.IndexOf(".png", StringComparison.OrdinalIgnoreCase) >= 0) return ImageFormat.PNG;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat redundant to the conditions above and has a potential of creating false positives.
A better approach would be to search for the last occurance of ., assume it separates the extension and look at the 3-4 following chars.
Have a look at UriHelper.IsGltfBinary for reference. It does the same for .gltf/.glb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of something like that but query strings can contain periods so that would still not resolve the issue.
The redundancy is another matter and will fix. Was a perhaps misguided attempt to have some holistic performance, since the majority of gltfs won't have query strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a specific fix to handle URL queries we could look from first "?" and forward to "." to find the file ending and compare that if you are worried about false positives for filenames or query strings with .png in them.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good to me!

…tart and then look for the file format before that. If no query string exsist we simply look at the end of the fpath.
@atteneder
Copy link
Owner

This looks good.

Usually I should have asked you in the first response to provide some unit test for this method (to make sure we don't break anything and don't miss corner cases), but I looked at it and decided this also needs to be restructured/refactored outside of the GLTFast class. I'm gonna merge now and do the refactor myself.

Thank you very much!

@atteneder atteneder merged commit 080ea8b into atteneder:main Apr 7, 2021
@atteneder
Copy link
Owner

@JonathanB-Vobling

fyi: unit tests would've been useful indeed: I wrote some and revealed cases that led to crashes!

See my commit to see what I changed.

Anyways, should be fine now. thanks

@JonathanB-Vobling JonathanB-Vobling deleted the file-format-fix branch April 9, 2021 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants