Issue with MotionPath/MotionEvent

Hi everybody,

I think I found an issue with MotionPath / MotionEvent classes.

It’s happening the following error:

com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
at java.util.ArrayList.rangeCheck(ArrayList.java:604)
at java.util.ArrayList.get(ArrayList.java:382)
at com.jme3.math.Spline.interpolate(Spline.java:288)
at com.jme3.cinematic.MotionPath.interpolatePath(MotionPath.java:94)
at com.jme3.cinematic.events.MotionEvent.onUpdate(MotionEvent.java:199)
at com.jme3.cinematic.events.MotionEvent.internalUpdate(MotionEvent.java:181)
at com.jme3.cinematic.events.MotionEvent.update(MotionEvent.java:164)
at com.jme3.scene.Spatial.runControlUpdate(Spatial.java:570)
at com.jme3.scene.Spatial.updateLogicalState(Spatial.java:688)
at com.jme3.scene.Node.updateLogicalState(Node.java:145)
at com.jme3.scene.Node.updateLogicalState(Node.java:152)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:244)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:722)

Here is what I’m doing:

[java]
final MotionPath path = new MotionPath();
path.addWayPoint(target.getNode().getLocalTranslation());
path.addWayPoint(new Vector3f(3, -2, 7));
path.setPathSplineType(Spline.SplineType.CatmullRom);

        MotionEvent motionControl = new MotionEvent(target.getNode(),path);
        motionControl.setDirectionType(MotionEvent.Direction.PathAndRotation);
        motionControl.setSpeed(12f);
        motionControl.play();

        path.addListener(new MotionPathListener() {
            public void onWayPointReach(MotionEvent control, int wayPointIndex) {
                if (path.getNbWayPoints() == wayPointIndex + 1) {
                   System.out.println("finish");
                }
            }
        });

[/java]

I have several targets in my scene. This error is intermitent. If we had more object/target in scene moving around, the problem occurs more frequently.

This problem is occurring in Jmonkey layer. I can’t protect or treat this error in game layer. It’s outside of my code.

Did someone see this problem? Could anyone help me?

Regards,

Tati

Works for me, doing it with 2000 targets the same time.
[java]
@Override
public void simpleInitApp()
{
flyCam.setMoveSpeed(80);
doit(2000);
}

private void doit(int i2)
{
    for (int i = 0; i < i2; i++)
    {
        final MotionPath path = new MotionPath();
        Geometry target;
        target = new Geometry("b", new Box(2, 3, 4));
        target.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
        rootNode.attachChild(target);
        path.addWayPoint(target.getLocalTranslation());
        path.addWayPoint(new Vector3f((float) (Math.random() * 10), (float) (Math.random() * 12), (float) (Math.random() * 14)));
        path.setPathSplineType(Spline.SplineType.CatmullRom);

        MotionEvent motionControl = new MotionEvent(target, path);
        motionControl.setDirectionType(MotionEvent.Direction.PathAndRotation);
        motionControl.setSpeed(1f);
        motionControl.play();

        path.addListener(new MotionPathListener()
        {
            public void onWayPointReach(MotionEvent control, int wayPointIndex)
            {
                if (path.getNbWayPoints() == wayPointIndex + 1)
                {
                    System.out.println("finish");
                }
            }
        });
    }
}[/java] 

What version do you use?

I got that once as well. I appears to happen if the 2 waypoints are the same location I think.

1 Like

Thanks netsky08 =D. We have some situations that we have 2 waypoints to the same locations. I will try to fix that in the code.

I will post here if it has solved the problem.

netsky08 you are right. It solved the problem. We spent 3 minutes to solved the problem with your tip. Thanks a lot. :slight_smile:

But Jmonkey should be prepared to treat this problem. It’s not friendly/elegant break the application. At least should use a try/catch to treat this exception.

Thanks people for your support.

gonna look into it.

Fixed in last revision

3 Likes

cool thanks! I can’t test it right now, but I guess there is nothing to worry about.

Just remember to close the issue ticket ;p

Awww man!!.. I had the same exception thrown and was pulling my hair out for hours until I found this thread! I was beginning to think I was crazy or something haha :stuck_out_tongue:

Thx for fixing it. Now it doesn’t crash at all anymore, it’s so relieving :smiley:

+1’ed the hero.

EDIT: Quick note, it still happens if you add two identical wayPoints (e.g.: when dynamically animating stuff on the scene, it may still happen that they are the same and throw that same out of bounds exception)

So here’s what I do now to make absolutely sure it never crashes (of course, it would be better to AVOID that entire animation if you can like using a IF branch or something):

[java]
MotionPath mypath = new MotionPath();
mypath.addWayPoint(item1.get_position().add(0, (item2.get_position().equals(item1.get_position()) ? 0.001f : 0), 0)); // Avoid IndexOutOfBoundsException
mypath.addWayPoint(item2.get_position());
[/java]