Stuck at animations phase, Blender 2.69

I have been stumped on this matter for a while, even after browsing these support boards, some issues have come close, but nothing has worked.

Problem: Nothing I output from Blender is allowed to animate in even the simplest animation control tests. For example, I went as far as making a simple 2 bone box to animate within the Hello Animation tutorial code. Even that did not work. It seems to have nothing to do with the meshes as I can load them all just fine, but somehow, cannot animate a simple box on 2 hinging bones. I would get the error:

Uncaught exception thrown in Thread[LWJGL Renderer Thread 5, main]
NullPointerException

Despite the error for my particularly simple animation, it loads all the library assets PERFECTLY fine.

What I assume I’m doing wrong might be in the .blend file, but as far as I can tell, I have copied every specific detail the documents have shown. Down to the root bone, making the action, setting parents, etc.

ANY help would be appreciated, I will even include the file I made just to test out the very basics of my issue.

The simple test box .blend (made in 2.69): http://www.sendspace.com/file/izovln
test code used: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_animation

A NullPointerException includes two useful pieces of information. It’s name (which you’ve included) and the stack trace. Arguably, the stack trace is the more important part.

With a stack trace we might be able to provide better guidance.

Thanks for your quick reply!

I wanted to avoid the stack trace because it loads the library models fine. The last topic that came close, after the stack trace, they boiled down to attacks on the person’s code being broken, and lost focus on the fact that maybe… there’s a problem in the individual’s blender model or model setup.

Here you are, this is all from Hello Animation’s code:

java.lang.NullPointerException
at mygame.Main.simpleInitApp(Main.java:40)
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:744)

the (40) Main.java line: control.addListener(this);

within:

@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.LightGray);
initKeys();
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
rootNode.addLight(dl);
player = (Node) assetManager.loadModel(“Models/BOX2/BOX2.j3o”);
player.setLocalScale(0.5f);
rootNode.attachChild(player);
control = player.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
channel.setAnim(“Action”);
}

Again, the Hello Animation code only breaks when I try to load my own model, which is nothing more than a root bone, and hinge bone with a box on it.

I have changed all the animation names to “Action” (it is a single, simple animation in my .blend) but I can’t even get past the initial load.

I do the same with Ninja and his “Idle1” animation and there are 0 issues. SInbad loads fine too when i do it with his “IdleTop” animation.

This:
control = player.getControl(AnimControl.class);

Is returning null.

Your ‘player’ may not have an AnimControl or (just as likely) it just isn’t in the root node. If you load the object in the scene explorer you can see which child the anim control is on.

1 Like

On a separate note, there was one user who manage to fix this error in a post last year by “moving AnimControl up”. From: http://hub.jmonkeyengine.org/forum/topic/uncaught-exception-thrown-in-threadlwjgl-renderer-thread5main-java-lang-null/page/2/

I would love to try doing the same, but I haven’t found out how to move around AnimControl in the j3o itself. If you pspeed or anyone have any input regarding that, it might just fix this error.

I’m just not understanding what we’re doing wrong in the .blend that AnimControl ends up in the wrong place, if that’s the reason behind this error.

The hierarchy of the j3o in that post is the same as mine:

Armature
—Cube
———Cube1
———AnimControl
——–——Action
———SkeletonControl

I have followed all the tutorials down to the tiniest detail as well.

Hey thanks a lot pspeed, while there was no way to fix how blender did the file hierarchy, I just did a rough work around with a few extra lines. Here is what I did that got my animations (on my cube and all other models) to work, although I’m not sure how plausible this method is, or maybe this is what all the cool kids are doing with their j3os:

FOR ALL THE WORLD TO SEE:

@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.LightGray);
initKeys();
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
rootNode.addLight(dl);
player = (Node) assetManager.loadModel(“Models/BOX2/BOX2.j3o”);
player.setLocalScale(0.5f);
Spatial x = player.getChild(“Cube”);
rootNode.attachChild(player);
control = x.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
channel.setAnim(“Action”);
}

I hope this either fixes other people who’s been having the same issues but aren’t very vocal about it, or maybe someone who stumbles upon this down the road. Any input on the “stability” of this method is appreciated as well.

1 Like
@cardboardman said: I hope this either fixes other people who's been having the same issues but aren't very vocal about it, or maybe someone who stumbles upon this down the road. Any input on the "stability" of this method is appreciated as well.

It comes up often. There was the same question only three days ago or so.

The other thing to remember is that you may have multiple anim controls in the hierarchy depending on how your model was built. There is no “fix” for this… it’s just the way it is.

@cardboardman said: Thanks for your quick reply!

I wanted to avoid the stack trace because it loads the library models fine. The last topic that came close, after the stack trace, they boiled down to attacks on the person’s code being broken, and lost focus on the fact that maybe… there’s a problem in the individual’s blender model or model setup.

Here you are, this is all from Hello Animation’s code:

java.lang.NullPointerException
at mygame.Main.simpleInitApp(Main.java:40)
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:744)

the (40) Main.java line: control.addListener(this);

within:

@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.LightGray);
initKeys();
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
rootNode.addLight(dl);
player = (Node) assetManager.loadModel(“Models/BOX2/BOX2.j3o”);
player.setLocalScale(0.5f);
rootNode.attachChild(player);
control = player.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
channel.setAnim(“Action”);
}

Again, the Hello Animation code only breaks when I try to load my own model, which is nothing more than a root bone, and hinge bone with a box on it.

I have changed all the animation names to “Action” (it is a single, simple animation in my .blend) but I can’t even get past the initial load.

I do the same with Ninja and his “Idle1” animation and there are 0 issues. SInbad loads fine too when i do it with his “IdleTop” animation.

@cardboardman : This code is working for me. I downloaded your model and used this code and its working. The hierarchy of the objects in the scene composer is also same as yours. I checked to be sure :slight_smile: .

here is my code:

[java]
package Main;

import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimEventListener;
import com.jme3.app.SimpleApplication;
import com.jme3.input.controls.ActionListener;
import com.jme3.light.DirectionalLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

/**
*

  • @author Kamran
    */
    public class BOX2 extends SimpleApplication implements ActionListener, AnimEventListener{

    Node player;
    private AnimChannel channel;
    private AnimControl control;

    public static void main(String args){
    BOX2 app = new BOX2();
    app.start();
    }

    @Override
    public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.LightGray);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
    rootNode.addLight(dl);
    player = (Node)assetManager.loadModel(“Models/BOX2/BOX2.j3o”);
    player.setLocalScale(0.5f);
    rootNode.attachChild(player);
    control = player.getControl(AnimControl.class);
    control.addListener(this);
    channel = control.createChannel();
    channel.setAnim(“Action”);
    }

    public void onAction(String name, boolean isPressed, float tpf) {

    }

    public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {

    }

    public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {

    }

}
[/java]

Just noticed the error in your code. In your one it says the line 40 is the error which is "Main.java line: control.addListener(this) ". I am not sure but I think if this is the error line then did you implement AnimEventListener ? :-? It would have been best if you post the whole class :slight_smile: .

@kamran said: Just noticed the error in your code. In your one it says the line 40 is the error which is "Main.java line: control.addListener(this) ". I am not sure but I think if this is the error line then did you implement AnimEventListener ? :-? It would have been best if you post the whole class :) .

A NullPointerException is only ever thrown for one reason and one reason only: a pointer was null. In this case the control was null.

You will not ever (ever) get a NullPointerException for class casts, or type errors, etc… Just for null pointers.

So, presuming some code is not incorrectly throwing its own NullPointerExceptions (never ever ever ever ever do this by the way) then you can 100000% guarantee that a NullPointerException indicates a null pointer was dereferenced.

oops my mistake. I thought cardboardman made a AnimEventListener parameter but its “control.addListener(this)” so yeah the AnimControl.class control may have been missing.

Hello kamran! Thanks for joining in. I noticed the way you easily loaded up the box the regular way, makes me wonder why some of us get this error and others do not.

I tested this by loading up your code, which you can run the box model without issues. I get the same nullpointer error.

All those poor souls who ask this question are probably from the group that gets this error, and I notice those who troubleshoot for them are usually from the group that does not get this error.

I wonder what’s different between our setups, is it JME3, the way we set up our environments, etc.

It can’t be blender if the hierarchy of the j3o is the same for both of our code. It can’t be the model if it loads for me and animates with the getChild lines added.

I guess for now it’ll be a mystery, or maybe… it’ll get solved out of this.

There are a few facts you can take away.

If there is no AnimControl on the root node of the model then no amount of getControl() will find it. You have to go to the child with the AnimControl.

If it works for someone then they are using a different j3o.

@pspeed said: If there is no AnimControl on the root node of the model then no amount of getControl() will find it. You have to go to the child with the AnimControl.

That is definitely be the best mindset to have; helped me realize getChild is the best course of action. (Thanks!)

But from the view of someone just cruising through the tutorials, getChild was mentioned very briefly in the Hello Node section, and just about all the assets/animation tutorials makes no mention of that.

Maybe this is where the most conflicts arise, as people who get this error load their models up for the first time (those rare, special cases like me), no tutorial can save them from it.

Perhaps some mention of it could be included in the tutorials, although, from checking this forum, its mainly an isolated few incidents here and there. Seeing as kamran can take my .blend, convert it to j3o, and fire it up with no error.

@cardboardman said: On a separate note, there was one user who manage to fix this error in a post last year by "moving AnimControl up". From: http://hub.jmonkeyengine.org/forum/topic/uncaught-exception-thrown-in-threadlwjgl-renderer-thread5main-java-lang-null/page/2/

I would love to try doing the same, but I haven’t found out how to move around AnimControl in the j3o itself. If you pspeed or anyone have any input regarding that, it might just fix this error.

I’m just not understanding what we’re doing wrong in the .blend that AnimControl ends up in the wrong place, if that’s the reason behind this error.

The hierarchy of the j3o in that post is the same as mine:

Armature
—Cube
———Cube1
———AnimControl
——–——Action
———SkeletonControl

I have followed all the tutorials down to the tiniest detail as well.

just to be sure. Does your hierarchy start from Armature or Cube? If it starts from Cube then the hierarchy is same as mine if it’s Armature then it is not. My hierarchy is

BOX2
-Material
-AnimControl
–Action
-SkeletonControl.

If you have the Armature Node then yes you should get an error. It is as pspeed said there is no AnimControl in that node that is why you are getting the null error. So you will have to go one step-down/getChild where the AnimControl is. Then in your case the AnimControl is at the Cube Node not the Armature Node. Here is an image of my hierarchy:

Hope it helps :slight_smile:

1 Like

Now that is the interesting part kamran, whenever I generate my j3o i get the entire hiearchy with it, which includes Armature there is even another path on top of that, which I’m not sure if its normal or not.

So in a finer detailing of how it looks to me:
[SceneExplorer Window]
———————————————————————
[update]
———————————————————————
—Models/BOX2/BOX2.blend
——Armature
———Cube
—————Cube1
—————AnimControl
————–——Action
—————SkeletonControl

It would clarify things for me greatly if you can explain if you just converted my box.blend purely as it was, or if you went through some extra steps.

The way it is currently this is how all my j3os get generated.

I appreciate the further input, thanks!

Here is what I did.

  1. I exported your model through ogre exporter from blender
  2. I then copied all the exported files to JME Models folder
  3. There I then converted the “.mesh.xml” file to .j3o from JME.
  4. (This is optional) I renamed the Cube.mesh.j30 to BOX2.j3o and alos the Cube-ogremesh Node to BOX2. This part does not matter you can keep as it is.

This is how I import models. :slight_smile:

1 Like

I can see that the AnimControl is still there in your hierarchy. In your case you just have to go a bit deeper to get the control.

Just the info I needed, I basically had to go the convert .blend directly to j3o route.

I was never able to go the ogre route since using 2.69.

Either way I guess there’s nothing broke about my modeling if someone else is able to convert to ogre. You know, from having a working ogre exporter. The one that you can install bundled with JME3 (for me) returns nothing but errors, the most recent one I can get from ogre works, but it causes another set of errors entirely.

Of course, that’s another can of worms I’d rather not open. Seems, as long as you have the right nodes, its all that really matters…

Much appreciated, thank you both.

1 Like
@pspeed said: It comes up often. There was the same question only three days ago or so.

The other thing to remember is that you may have multiple anim controls in the hierarchy depending on how your model was built. There is no “fix” for this… it’s just the way it is.

Sorry to intervene in the topic.

Would a “frequent errors” guide be helpful do you think? I’d happily start that for dealing with model importing, it might save a lot of time you guys replying individually to a lot of the same problems.

1 Like