glTFast icon indicating copy to clipboard operation
glTFast copied to clipboard

glTFast raises IndexOutOfRangeException when loading GLB with WebP textures

Open mhama opened this issue 1 year ago • 1 comments

Describe the bug glTFast raises IndexOutOfRangeException when loading GLB file with WebP textures using LoadGltfBinary method. I know that WebP format is not supported but raising IndexOutOfRangeException is not nice behaviour.

Official support for WebP texture is also welcome. (There's PR https://github.com/atteneder/glTFast/pull/632)

Files

plateau_sample_webp.zip This file is from PLATEAU project.

To Reproduce

Load above GLB file with (Unity) gltFast v6.7.0 LoadGltfBinary method.

Expected behavior

It should fail gracefully, like returning false from LoadGltfBinary method, or some kind of NotImplemented exception. Or, just succeed with some warnings.

CallStack

When gamma color space System.IndexOutOfRangeException: Index was outside the bounds of the array. at GLTFast.GltfImportBase.LoadImages (System.Uri baseUri) [0x0025e] in C:\Users\hammmm\Documents\Projects\PLATEAUStreamingTest1\Library\PackageCache\[email protected]\Runtime\Scripts\GltfImport.cs:1390 at GLTFast.GltfImportBase.LoadGltfBinaryBuffer (System.Byte[] bytes, System.Uri uri) [0x0041c] in C:\Users\hammmm\Documents\Projects\PLATEAUStreamingTest1\Library\PackageCache\[email protected]\Runtime\Scripts\GltfImport.cs:1867 at GLTFast.GltfImportBase.LoadGltfBinary (System.Byte[] bytes, System.Uri uri, GLTFast.ImportSettings importSettings, System.Threading.CancellationToken cancellationToken) [0x0005f] in C:\Users\hammmm\Documents\Projects\PLATEAUStreamingTest1\Library\PackageCache\[email protected]\Runtime\Scripts\GltfImport.cs:582

The code around the exception GltfImport.cs

1389                    var imageIndex = txt.GetImageIndex(); // <----- imageIndex = -1
1390                    if (imageVariants[imageIndex] == null) // <----- IndexOutOfRangeException
1391                    {
1392                       imageVariants[imageIndex] = new HashSet<int>();
1393                    }

If the mode is linear, the position of exception is different, but basically the same error occurs.

Desktop (please complete the following information):

  • glTFast version : 6.7.0 (Unity)
  • Unity Editor version : 2021.3.22f1
  • Render Pipeline and version : Built-In
  • Platform: Editor
  • OS: Windows 11

mhama avatar Jul 27 '24 10:07 mhama

Having the same issue.

I also noticed that this issue only occurs if you include/enable the EXT_texture_webp in the .glb. But if you remove that then it will still import the model just without textures (and with some textures errors). But to me this is a much better way of handling it, the System.IndexOutOfRangeException: Index was outside the bounds of the array. error makes the asset completely unusable. Screenshot 2024-08-28 102323 Screenshot 2024-08-28 102350

It would be great if the handling of this could be improved.

HarrisonHough avatar Aug 28 '24 07:08 HarrisonHough

Agreed, this has to be handled better.

For the record: with the provided glb file glTFast (6.7.1) rejects to load it properly, as the WebP extension is listed as required. Once removed from the required list the error is reproducible.

I found a fix (the problem is actually in the JSON parsing code). Expect it to land in the next release.

Thanks a lot for reporting!

atteneder avatar Sep 03 '24 18:09 atteneder