KinematicRagdollControl null pointer

I am make characters in my game have a ragdoll effect when they die so I followed the test case in jme3-Tests. This is my ragdoll code:

ragdoll = new KinematicRagdollControl(1f);
setUpBones();
Soldier.addControl(ragdoll);
bulletAppState.getPhysicsSpace().add(ragdoll);
ragdoll.setEnabled(false);

public void setUpBones(){
ragdoll.addBoneName(“spine”);
ragdoll.addBoneName(“chest”);
ragdoll.addBoneName(“neck”);
ragdoll.addBoneName(“shoulder.L”);
ragdoll.addBoneName(“shoulder.R”);
ragdoll.addBoneName(“head”);
ragdoll.addBoneName(“upper_arm.L”);
ragdoll.addBoneName(“forearm.L”);
ragdoll.addBoneName(“hand.L”);
ragdoll.addBoneName(“upper_arm.R”);
ragdoll.addBoneName(“forearm.R”);
ragdoll.addBoneName(“hand.R”);
ragdoll.addBoneName(“hips”);
ragdoll.addBoneName(“thigh.L”);
ragdoll.addBoneName(“thigh.R”);
ragdoll.addBoneName(“shin.L”);
ragdoll.addBoneName(“foot.L”);
ragdoll.addBoneName(“toe.L”);
ragdoll.addBoneName(“heel.L”);
ragdoll.addBoneName(“heel.02.L”);
ragdoll.addBoneName(“shin.R”);
ragdoll.addBoneName(“foot.R”);
ragdoll.addBoneName(“heel.R”);
ragdoll.addBoneName(“toe.R”);
ragdoll.addBoneName(“heel.02.R”);
}
However when I run it, I get:
java.lang.NullPointerException
at com.jme3.scene.Spatial.addControl(Spatial.java:591)
at com.jme3.bullet.control.KinematicRagdollControl.setSpatial(KinematicRagdollControl.java:331)
at com.jme3.scene.Spatial.addControl(Spatial.java:591)
at mygame.Enemy.createSoldier(Enemy.java:89)
at mygame.Enemy.<init>(Enemy.java:61)
at mygame.Main.setUpMap(Main.java:391)
at mygame.Main.simpleInitApp(Main.java:130)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225)
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:662)
Did I set something incorrectly?

1 Like

Is this the stable release?
I couldn’t find anything useful on that line in the branch named 3,0final (neither in trunk)

https://code.google.com/p/jmonkeyengine/source/browse/branches/3.0final/engine/src/core/com/jme3/scene/Spatial.java#591

@jmaasing said: Is this the stable release? I couldn't find anything useful on that line in the branch named 3,0final (neither in trunk)

Google Code Archive - Long-term storage for Google Code Project Hosting.

Yes, I have all the latest updates of jmonkey installed, and no nightly builds. I tried it with the Ogre test character that is integrated in basic game and it worked fine with just: ragdoll = new KinematicRagdollControl(.5f);
Soldier.addControl(ragdoll);

            bulletAppState.getPhysicsSpace().add(ragdoll);

This worked so I did the same (where I don’t maually set up the bones) to my model. There is an Anim and Skeleton Control in the model hierarchy and all the bones are named and there, but I still get the NPE on my model. Any suggestions?

1 Like
@Jmonkier said: Yes, I have all the latest updates of jmonkey installed, and no nightly builds.

…well, for some reason, the library you are actually running against is not the latest final release. Nor is it the latest trunk either.

In fact, I have to go all the way back to a 1.5 year old version to find the right line of code:
https://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/scene/Spatial.java?r=9838#591

So you are not running from a downloaded 3.0, I guess. Maybe you are running rc2 or something?

Anyway, the null pointer exception is because KinematicRagdollControl.setSpatial(KinematicRagdollControl.java:331) is adding a null control for some reason. But the code you are running against is so old there is no telling what has been fixed since then.

@pspeed said: ...well, for some reason, the library you are actually running against is not the latest final release. Nor is it the latest trunk either.

In fact, I have to go all the way back to a 1.5 year old version to find the right line of code:
https://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/scene/Spatial.java?r=9838#591

So you are not running from a downloaded 3.0, I guess. Maybe you are running rc2 or something?

Anyway, the null pointer exception is because KinematicRagdollControl.setSpatial(KinematicRagdollControl.java:331) is adding a null control for some reason. But the code you are running against is so old there is no telling what has been fixed since then.


What do you mean by “the code I am running against”? I am certain I have rc 3, and I found the rag doll implementation from the jme3 tests project. The part I don’t understand is the using the ogre model that is in the jme3 test library works fine versus my model. My model was exported through blender and converted to a .j3o like normal.

1 Like

I mean that the actual JME jars that you are using are 1.5 years old. It is tough for us to support such old code.

If I am running the latest release of the Sdk how do I update my lib jars =D

1 Like
@Jmonkier said: If I am running the latest release of the Sdk how do I update my lib jars =D

I’m not sure how you could be running the latest, actually. And you said “rc 3” which I’m not sure what it means.

You could try uninstalling your SDK and downloading the actual 3.0 version from the downloads page and then updating the plugins. This should get you to 3.0.5 or so.

In the log messages that spit out to the SDK console, what version does it say you are running there?

For example, my dev version says:
[java]
run:
Feb 28, 2014 12:42:07 PM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.x
[/java]

Yours should say 3.0.4 or 3.0.5 or so if you are running the latest or near-latest code.

@pspeed said: I'm not sure how you could be running the latest, actually. And you said "rc 3" which I'm not sure what it means.

You could try uninstalling your SDK and downloading the actual 3.0 version from the downloads page and then updating the plugins. This should get you to 3.0.5 or so.

In the log messages that spit out to the SDK console, what version does it say you are running there?

For example, my dev version says:
[java]
run:
Feb 28, 2014 12:42:07 PM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.x
[/java]

Yours should say 3.0.4 or 3.0.5 or so if you are running the latest or near-latest code.


It turns out that I did in fact have 3.0.0 beta so I re downloaded the lastest stable release but I am still getting the NPE.
java.lang.NullPointerException
at com.jme3.scene.Spatial.addControl(Spatial.java:602)
at com.jme3.bullet.control.KinematicRagdollControl.createSpatialData(KinematicRagdollControl.java:359)
at com.jme3.bullet.control.AbstractPhysicsControl.setSpatial(AbstractPhysicsControl.java:174)
at com.jme3.scene.Spatial.addControl(Spatial.java:602)
at mygame.Enemy.createSoldier(Enemy.java:101)
at mygame.Enemy.<init>(Enemy.java:70)
at mygame.Main.setUpMap(Main.java:487)
at mygame.Main.simpleInitApp(Main.java:151)
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)

1 Like
@Jmonkier said: It turns out that I did in fact have 3.0.0 beta so I re downloaded the lastest stable release but I am still getting the NPE. java.lang.NullPointerException at com.jme3.scene.Spatial.addControl(Spatial.java:602) at com.jme3.bullet.control.KinematicRagdollControl.createSpatialData(KinematicRagdollControl.java:359) at com.jme3.bullet.control.AbstractPhysicsControl.setSpatial(AbstractPhysicsControl.java:174) at com.jme3.scene.Spatial.addControl(Spatial.java:602) at mygame.Enemy.createSoldier(Enemy.java:101) at mygame.Enemy.<init>(Enemy.java:70) at mygame.Main.setUpMap(Main.java:487) at mygame.Main.simpleInitApp(Main.java:151) 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)

Yes, but now it is easier to find the real problem.

Your spatial does not have a SkeletonControl.

Edit: For reference:
http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/bullet-common/com/jme3/bullet/control/KinematicRagdollControl.java#359
https://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/scene/Spatial.java?r=10824#602

Maybe we should throw an UnsupprtedOperationException when the SkeletonControl is null.

Personally I would use IllegalStateException, it is more suited I think:
http://docs.oracle.com/javase/7/docs/api/java/lang/IllegalStateException.html

Collections API uses Unsupported… but they also have a method you can use to check if you should even bother calling e.g. add methods. In this case I feel it is more a question of the state of the data rather than if the addControl is supported or not.

But I have pretty strong opinions on how to do Exceptions and I’m usually alone in a corner muttering: “madness! they. don’t. get. it.” :smiley:

@pspeed said: Yes, but now it is easier to find the real problem.

Your spatial does not have a SkeletonControl.

Edit: For reference:
http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/bullet-common/com/jme3/bullet/control/KinematicRagdollControl.java#359
Google Code Archive - Long-term storage for Google Code Project Hosting.


I am 100% certain I have a skeleton control in my model. i have an armature, which the mesh is parented under, and at the bottom of the tree is the Anim, Skeleton, and geometry.

1 Like
@pspeed said: Yes, but now it is easier to find the real problem.

Your spatial does not have a SkeletonControl.

Edit: For reference:
http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/bullet-common/com/jme3/bullet/control/KinematicRagdollControl.java#359
Google Code Archive - Long-term storage for Google Code Project Hosting.

One thing I just dicovered though is that if I don’t convert the model to a .j3o, I can use the skeleten.xml and that seems to work. Im not sure is this is a bug, but I need to be able to open the model in the scene composer and this way doesn’t allow that to happen.

1 Like
@Jmonkier said: I am 100% certain I have a skeleton control in my model. i have an armature, which the mesh is parented under, and at the bottom of the tree is the Anim, Skeleton, and geometry.

You may have a skeletcon control “somewhere in the model” but given your stack trace, I’m 100% sure that you do not have a skeleton control at the root of the model.

@nehon said: Maybe we should throw an UnsupprtedOperationException when the SkeletonControl is null.

Just use a RuntimeException, I guess. I’m not sure anyone is going to be catching it and even if they are, the suggestions so far are not really ‘catchable’ in any ‘I can do something with it’ sense.

Technically, it’s an IllegalArgumentException anyway. You’ve passed an argument that is incorrect… in this case a Spatial with no skeleton. But I’m not sure it makes the error any clearer to use that exception.

1 Like

IllegalArgumentException is even better, the exception class might not say more than a NPE but the message could.

@jmaasing said: IllegalArgumentException is even better, the exception class might not say more than a NPE but the message could.

Yep, no matter what… message is the key. :slight_smile:

@pspeed said: You may have a skeletcon control "somewhere in the model" but given your stack trace, I'm 100% sure that you do not have a skeleton control at the root of the model.
Ok, so the way I got it at the root was by converting the .mesh.xml into a j3o which put the controls at the root and it seemed to work. It seems like the ragdoll should be able to find the control anywhere in the children though.
1 Like

Yeah maybe it should make a recursive search through the children.

1 Like