JointController IndexOutOfBoundsException for ms3d

Hi guys,



I've been lurking for a while but this is my first post, so I apologize in advance if I'm duplicating messages. I promise I did try search first!



When loading an ms3d file which has a skeleton and either zero or one keyframe(s) (using the same code as in TestMilkJmeWrite), I was getting the following exception:



SEVERE: Exception in game loop

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

at java.util.ArrayList.RangeCheck(Unknown Source)

at java.util.ArrayList.get(Unknown Source)

at com.jmex.model.animation.JointController.processController(JointController.java:427)

at com.jmex.model.animation.JointController.read(JointController.java:705)

at com.jme.util.export.binary.BinaryImporter.readObject(BinaryImporter.java:247)

at com.jme.util.export.binary.BinaryInputCapsule.resolveIDs(BinaryInputCapsule.java:457)

at com.jme.util.export.binary.BinaryInputCapsule.readSavableArray(BinaryInputCapsule.java:445)

… etc



I had a look, and made a slight change to code which appears to have fixed it. The change was in JointController.processController(), as follows:



Was:

        if (movementInfo.size() == 1) { // IE no times were added or only time 0

            // was added

            movementInfo.add(0, new PointInTime(0));

        }





Now:

        if (movementInfo.size() <= 1) { // IE no times were added or only time 0

            // was added

            movementInfo.add(0, new PointInTime(numJoints));

        }





I can provide some sample ms3d files which suffer the problem if that is of assistance to you.



Thanks for a great engine btw, I expect I'll be back with a lot of questions once I get past my first few experimental steps!

I'm surprised that would work…  I'd expect you'd have to test for 0 size and do an add with no index param.

Well the out of bounds was happening because it was trying to load the positions for each joint in turn from the first PointInTime, but there was no records for it to read from. Giving it numJoints just meant that it had the right number of joints, and each of them was defaulting to 0 (or null, I forget, but it was able to handle it then). Changing the == to <= just meant that it caught the zero-keyframe case as well.



I'm not sure if this is the right answer, just that it is an answer which might have been of use in the debugging process. :slight_smile: