mgsx-dev / gdx-gltf

GLTF 2.0 3D format support and PBR shader implementation for LibGDX
Apache License 2.0
214 stars 50 forks source link

Possible 'ArrayIndexOutOfBoundsException' with WeightVector() #86

Closed BitsAtPlayDev closed 1 year ago

BitsAtPlayDev commented 1 year ago

The property count and values.length can have different values leading to ArrayIndexOutOfBoundsException because when looping through values, count is often used instead of values.length

The difference can occur when creating a new instance of WeightVector, and only nbWeights is specified, causing max to default to 8. This leads to count getting set to whatever nbWeights is, while values.length == 8

Places where only nbWeights is specified: AnimationLoader, MeshLoader & CubicWeightVector classes.

Places where count is used to loop through values: WeightVector & GTLFTypes classes

The exception below occurred when attempting to load a model where an nbWeights > 8 was encountered. Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 8 out of bounds for length 8 at net.mgsx.gltf.loaders.shared.GLTFTypes.map(GLTFTypes.java:105) at net.mgsx.gltf.loaders.shared.animation.AnimationLoader.load(AnimationLoader.java:164) at net.mgsx.gltf.loaders.shared.animation.AnimationLoader.load(AnimationLoader.java:37) at net.mgsx.gltf.loaders.shared.GLTFLoaderBase.load(GLTFLoaderBase.java:129) at net.mgsx.gltf.loaders.glb.GLBLoader.load(GLBLoader.java:16) at net.mgsx.gltf.loaders.glb.GLBAssetLoader.loadSync(GLBAssetLoader.java:32) at net.mgsx.gltf.loaders.glb.GLBAssetLoader.loadSync(GLBAssetLoader.java:14) [...]

MikOfClassX commented 1 year ago

We have this issue on some models. Therefore we're also investigating on that as it's a show stopper in many cases.

MikOfClassX commented 1 year ago

@dar-dev of ClassX did a great fix: https://github.com/mgsx-dev/gdx-gltf/pull/98 At last we're able to load any edg-case model flawlessly.