Error while trying to animate model

Hello.

I’m trying to animate an Ogre model from the SceneComposer. I have imported this model:

Model

I’m getting this error:

The model works fine using OgreMeshy, it’s displayed correctly and animations work perfect.
I’ve tried different jMonkeyEngine versions: stable, latest nightly build, but I still have this error.

Nothing? :S

If it helps, here’s the exception thrown when I try to animate in run time:

[java]SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.Main.simpleUpdate(Main.java:160)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:242)
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)[/java]

The error is in your code at:
mygame.Main.simpleUpdate(Main.java:160)

I guess we’d have to see that line of code to even begin to guess.

@pspeed said: The error is in your code at: mygame.Main.simpleUpdate(Main.java:160)

I guess we’d have to see that line of code to even begin to guess.

It’s mind blowing how basic stack trace reading is an unknown art.

@madjack said: It's mind blowing how basic stack trace reading is an unknown art.

Heheh… well, it just makes the fact that I can solve any NPE in 30 seconds or less that much more impressive. :slight_smile:

To be fair, some of the people who come to me with NPE issues already understand what’s null and they just don’t know why… that’s where the fun part of the puzzle is. My sub-five minute average is still pretty high even on those.

@pspeed said: To be fair, some of the people who come to me with NPE issues already understand what's null and they just don't know why
Fair or providing excuses? ;) I'm teasing.

But, it’s not a stretch to just read a line and see that the number actually refers to a line number in the mentioned class.

My sub-five minute average is still pretty high even on those.

Give me a NPE over an “out of thread updated (root)node” that you have to diagnose for someone else ANY. TIME.

@madjack said: Fair or providing excuses? ;) I'm teasing.

But, it’s not a stretch to just read a line and see that the number actually refers to a line number in the mentioned class.

Give me a NPE over an “out of thread updated (root)node” that you have to diagnose for someone else ANY. TIME.

Indeed.

First imagine that you have some server software that deals with multiple threads, multiple clients, multiple resources… all through nice service-layer abstractions and so on.

Now, imagine said application decides to randomly deadlock under certain resource loads.

Now, imagine this is before Ctrl-Brk would simply tell you where the deadlock is. (Also, even debuggers were relatively primitive at this time and in any case, hard to run in the distributed environment.)

Man, I had reams of paper where I’d tracked the call stack from top to bottom, all through every layer of the app, noting the order locks/monitors were acquired trying to figure out who was doing it out of order. It finally came down to one case where class B was synching before calling class A when generally it was the other way around. There is a very good reason that I champion lock-free threading designs… the “synchronized” keyword triggers post-traumatic-stress-disorder. (Even more off topic, if you ever have one synchronized block calling into another synchronized block… just go ahead and pull out all of your hair right now. ;))

Relatively speaking, the out of order update exceptions don’t bother me too much. :slight_smile: (BTW, there is kind of a trick to forcing them to happen if it’s a random timing issue… Won’t tell you where it is but it makes it more consistently fire in cases where something is wrong.)

@pspeed said: the out of order update exceptions don't bother me too much.

Unless you’ve made LOTS of changes to the scene graph it’s not a huge deal to find the problem, but it’s always annoying to have to get to the root cause of the problem.

/ end of hijack. :wink:

@pspeed said: The error is in your code at: mygame.Main.simpleUpdate(Main.java:160)

I guess we’d have to see that line of code to even begin to guess.

The error is not in my code… I was able to use the same code with another models and, as I said before, I got the same error when I try to animate it in the scene composer.

:S

And by the way, just because I called a function that threw an error doesn’t mean the error is in my code…

Oh, sorry, my mistake. I copied the wrong error.

At first I was like WTF??? but now I’m seeing it…

Anyway, can someone please test the model I uploaded? Is just importing it and playing the animation from the SDK.

Works fine. shrug

I’m heavily into testing and I couldn’t really take the time to do that with your model, but I did notice the head somewhat bobbing a bit. But I didn’t spend more than 5 mins on the whole thing.

@gonzalofarias1 said: And by the way, just because I called a function that threw an error doesn't mean the error is in my code...

I think you already figured this out but just to be sure… the above statement implies that you are reading the stack trace upside down. The top line is the one where the actual error is. So if there is an NPE on that top line (the one I quoted previously) then it is because there is an NPE on that line. Not in a called function. On that exact line there is a bug of trying to deference a null pointer.

@pspeed said: I think you already figured this out but just to be sure... the above statement implies that you are reading the stack trace upside down. The top line is the one where the actual error is. So if there is an NPE on that top line (the one I quoted previously) then it is because there is an NPE on that line. Not in a called function. On that exact line there is a bug of trying to deference a null pointer.

Yes, the problem is that in the stack trace of the error I’m getting is not like that. But, as I said before, I pasted another error.

So yeah, sorry about that. :slight_smile:

@madjack said: Works fine. *shrug*

I’m heavily into testing and I couldn’t really take the time to do that with your model, but I did notice the head somewhat bobbing a bit. But I didn’t spend more than 5 mins on the whole thing.

Did you try animating it in the Scene Composer? It works fine just placing it in a scene, but when you animate it throws an error.

@pspeed this is the correct stack trace:

[java]ene 22, 2014 7:53:38 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.Main.simpleInitApp(Main.java:113)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:226)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:722)[/java]

[java]public void simpleInitApp() {

    // You must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    rootNode.addLight(sun);
    
    Spatial scene = assetManager.loadModel("Scenes/newScene.j3o");
    rootNode.attachChild(scene);
    
    final int SHADOWMAP_SIZE=1024;
    DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 3);
    dlsr.setLight(sun);
    viewPort.addProcessor(dlsr);
    
    dlsf = new DirectionalLightShadowFilter(assetManager, 1024, 3);
    dlsf.setLight(sun);
    dlsf.setEnabled(true);
    
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(dlsf);
    viewPort.addProcessor(fpp);
    
    player = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.j3o"); 

//I downloaded this model from the official Ogre site (a Blender file), then I
//converted it using the latest exporter.
player.setShadowMode(RenderQueue.ShadowMode.Cast);
scene.setShadowMode(RenderQueue.ShadowMode.Receive);

    Node playerCamContainer = new Node();
    rootNode.attachChild(playerCamContainer);
    
    rootNode.attachChild(player);
    player.setLocalTranslation(10, 10, 10);
    
    // Disable the default flyby cam
    flyCam.setEnabled(false);
    //create the camera Node
    //camNode = new CameraNode("Camera Node", cam);
    //This mode means that camera copies the movements of the target:
    //camNode.setControlDir(ControlDirection.SpatialToCamera);
    //Attach the camNode to the target:
    //player.attachChild(camNode);
    //.getParent().attachChild(camNode);
    //Move camNode, e.g. behind and above the target:
    ChaseCamera chaseCam = new ChaseCamera(cam, player, inputManager);
    //Rotate the camNode to look at the target:
    //camNode.lookAt(player.getLocalTranslation(), Vector3f.UNIT_Y);
    
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    
    playerControl = new BetterCharacterControl(1,1.8f,50);

// Attach physical properties to model and PhysicsSpace
player.addControl(playerControl);
bulletAppState.getPhysicsSpace().add(playerControl);
bulletAppState.getPhysicsSpace().add(rootNode.getChild(“terrain-newScene”).getControl(RigidBodyControl.class));

    control = player.getChild(0).getControl(AnimControl.class);
    control.addListener(this);   // <<--This is the line firing the exception
    channel = control.createChannel();
    channel.setAnim("my_animation");
    
    initKeys();
}[/java]

edit: i see you put a comment in there saying which line 113 is… im betting that player.getChild(0) does not have a Control called AnimControl and thats your problem. getControl() returns null if the spatial does not have that control added to it.

you’ll need to do a little investigation in to your scenegraph and see which spatial has the control youre looking for.

I’m also getting the SceneComposer error from the first post. Exact same thing with the OPs model and I haven’t even done any coding yet so that’s not it.

Changing the animation of the AnimControl in the properties windows throws the error.

Using a fresh install of JMonkey stable and using the supplied Blender I had some issues exporting the models. I installed the Ogre exporter from the JMonkey tools menu and it threw an error on export in Blender. Googling the error revealed a conflict between newer versions of blender and the exporter so I downloaded the current version from the repo and it appears to work fine.

Is there a known working model anywhere I can try out?

@causticcuddles said: I'm also getting the SceneComposer error from the first post. Exact same thing with the OPs model and I haven't even done any coding yet so that's not it.

Changing the animation of the AnimControl in the properties windows throws the error.

Using a fresh install of JMonkey stable and using the supplied Blender I had some issues exporting the models. I installed the Ogre exporter from the JMonkey tools menu and it threw an error on export in Blender. Googling the error revealed a conflict between newer versions of blender and the exporter so I downloaded the current version from the repo and it appears to work fine.

Is there a known working model anywhere I can try out?

Finally! Someone who could reproduce it. :slight_smile:

Yeah. Wasn’t trying to.

I’ve tried showing the model in code with no success, but I do get a stack trace! Oh happy day.
This error occurs when doing AnimChannel.setAnim(“walk”);

[java]java.lang.ArrayIndexOutOfBoundsException: -3
at com.jme3.animation.CompactVector3Array.deserialize(CompactVector3Array.java:95)
at com.jme3.animation.CompactVector3Array.deserialize(CompactVector3Array.java:42)
at com.jme3.animation.CompactArray.get(CompactArray.java:132)
at com.jme3.animation.BoneTrack.setTime(BoneTrack.java:232)
at com.jme3.animation.Animation.setTime(Animation.java:110)
at com.jme3.animation.AnimChannel.update(AnimChannel.java:395)
at com.jme3.animation.AnimControl.controlUpdate(AnimControl.java:332)
at com.jme3.scene.control.AbstractControl.update(AbstractControl.java:112)
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) [/java]