Browse Source

avoid an NPE in GltfLoader.findChildren() (#1471)

* Update GltfLoader.java

null pointer exception if the GLTF file references a node that doesn't exist.
I got this problem while tring to convert my GLTF file, i got 440 animations on the file with 3 animation that have joint index missmatch.
Maybe it's better to log the errors detail so the user have all the information to correct the error

* Update GltfLoader.java

* format added code per the proposal at PR #1098

* log any missing JointWrapper

This seems to be how model issues are reported by GltfLoader.

Co-authored-by: Stephen Gold <[email protected]>
Xenokieser 3 years ago
parent
commit
f0dd68b746

+ 6 - 0
jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java

@@ -1085,6 +1085,12 @@ public class GltfLoader implements AssetLoader {
 
     private void findChildren(int nodeIndex) throws IOException {
         JointWrapper jw = fetchFromCache("nodes", nodeIndex, JointWrapper.class);
+        if (jw == null) {
+            logger.log(Level.WARNING,
+                    "No JointWrapper found for nodeIndex={0}.", nodeIndex);
+            return;
+        }
+
         JsonObject nodeData = nodes.get(nodeIndex).getAsJsonObject();
         JsonArray children = nodeData.getAsJsonArray("children");