AxisRods setModelBound throws unexpected NullPointerException


  • Operating System: Linux Gentoo

  • Java Run Time version: java version "1.5.0_10"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
    Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixed mode)

  • jMonkeyEngine version: 0.11

  • LWJGL version: 1.0



I was working on my test and added AxisRods to debug a bone position/rotation. AxisRods does not render then I added a setModelBound() method to see if I was able to make it visible. I got this:

May 3, 2007 3:33:32 AM com.jme.app.BaseGame start
INFO: Application started.
May 3, 2007 3:33:32 AM com.jme.system.PropertiesIO <init>
INFO: PropertiesIO created
May 3, 2007 3:33:32 AM com.jme.system.PropertiesIO load
INFO: Read properties
May 3, 2007 3:33:32 AM com.jme.app.BaseSimpleGame initSystem
INFO: jME version 0.11 beta
May 3, 2007 3:33:32 AM com.jme.input.joystick.DummyJoystickInput <init>
INFO: Joystick support is disabled
May 3, 2007 3:33:32 AM com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
May 3, 2007 3:33:32 AM com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W:  640H: 480
May 3, 2007 3:33:33 AM com.jme.app.BaseSimpleGame initSystem
INFO: Running on: null
Driver version: null
NVIDIA Corporation - GeForce 7300 GS/PCI/SSE2 - 2.0.2 NVIDIA 87.76
May 3, 2007 3:33:33 AM com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
May 3, 2007 3:33:33 AM com.jme.util.lwjgl.LWJGLTimer <init>
INFO: Timer resolution: 1000 ticks per second
May 3, 2007 3:33:33 AM com.jme.scene.Node <init>
INFO: Node created.
May 3, 2007 3:33:33 AM com.jme.scene.Node <init>
INFO: Node created.
May 3, 2007 3:33:33 AM com.jme.scene.Node attachChild
INFO: Child (FPS label) attached to this node (FPS node)
May 3, 2007 3:33:33 AM com.jme.scene.Node <init>
INFO: Node created.
May 3, 2007 3:33:33 AM com.jme.scene.Node <init>
INFO: Node created.
May 3, 2007 3:33:33 AM com.jme.scene.Node <init>
INFO: Node created.
May 3, 2007 3:33:33 AM com.jme.scene.Node <init>
INFO: Node created.
May 3, 2007 3:33:33 AM com.jme.scene.Node attachChild
INFO: Child (Bone 2) attached to this node (Bone)
java.lang.NullPointerException
at com.jme.scene.shape.AxisRods.setModelBound(Unknown Source)
at org.md5reader2.test.TestBoneAnimation.simpleInitGame(TestBoneAnimation.java:83)
at com.jme.app.BaseSimpleGame.initGame(Unknown Source)
at com.jme.app.BaseGame.start(Unknown Source)
at org.md5reader2.test.TestBoneAnimation.main(TestBoneAnimation.java:201)
May 3, 2007 3:33:33 AM com.jme.app.BaseSimpleGame cleanup
INFO: Cleaning up resources.
May 3, 2007 3:33:33 AM com.jme.app.BaseGame start
INFO: Application ending.

This is the code of my class. This Exception output was thrown with the AxisRods attached to rootNode as you can see in the code. But I got the same result with the AxisRods attached to the bone node.

package org.md5reader2.test;

import com.jme.animation.AnimationController;
import com.jme.animation.Bone;
import com.jme.animation.BoneAnimation;
import com.jme.animation.BoneTransform;
import com.jme.animation.SkinNode;
import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.math.Matrix3f;
import com.jme.math.Matrix4f;
import com.jme.math.Quaternion;
import com.jme.math.TransformMatrix;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Controller;
import com.jme.scene.Node;
import com.jme.scene.shape.AxisRods;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Capsule;
import com.jme.scene.state.MaterialState;
import com.jme.util.BoneDebugger;

public class TestBoneAnimation extends SimpleGame {

   @Override
   protected void simpleInitGame() {
      Node model = new Node("Model");

      Box testBox = new Box("Test Box", new Vector3f(0, 0, 0), 2f, .5f, .5f);
      testBox.setModelBound(new BoundingBox());
      testBox.updateModelBound();

      Bone bone = new Bone("Bone");
      AxisRods ar = new AxisRods("Bone's Axis");
      
      Bone bone2 = new Bone("Bone 2");
      
      bone.attachChild(bone2);
      bone.updateGeometricState(0, true);

      Vector3f axisX = new Vector3f(1f, 0f, 0f);
      Vector3f axisY = new Vector3f(0f, 1f, 0f);
      Vector3f axisZ = new Vector3f(0f, 0f, 1f);

      Quaternion b1Q1 = new Quaternion().fromAngleAxis(0f, axisZ);
      Quaternion b1Q2 = new Quaternion().fromAngleAxis(0f, axisY);
      Quaternion b1Q3 = new Quaternion().fromAngleAxis(0f, axisX);
      bone.setLocalRotation(b1Q1.mult(b1Q2).mult(b1Q3));
      bone.setLocalTranslation(new Vector3f(0.0f, 0.0f,
            0.0f));

      Quaternion b2Q1 = new Quaternion().fromAngleAxis(0f, axisZ);
      Quaternion b2Q2 = new Quaternion().fromAngleAxis(0f, axisY);
      Quaternion b2Q3 = new Quaternion().fromAngleAxis(0f, axisX);
      bone2.setLocalRotation(b2Q1.mult(b2Q2).mult(b2Q3));
      bone2.setLocalTranslation(new Vector3f(0.0f, 2.0f,
            0.0f));

      ar.setModelBound(new BoundingBox());
      ar.updateModelBound();
      
      MaterialState arMs = display.getRenderer().createMaterialState();
      arMs.setDiffuse(ColorRGBA.cyan);
      ar.setRenderState(arMs);
      ar.updateRenderState();
      
      ar.setLocalTranslation(0f, 0f, 0f);
      ar.setLocalScale(10f);
      ar.updateGeometricState(0, true);
      
      bone.updateGeometricState(0, true);

      model.attachChild(bone);

      rootNode.attachChild(model);
      rootNode.attachChild(ar);

      BoneTransform boneTrans = new BoneTransform();
      BoneAnimation boneAnim = new BoneAnimation("Bone Animimation");
      AnimationController ac = new AnimationController();

      Quaternion[] rotations = new Quaternion[5];
      Vector3f[] translations = new Vector3f[5];

      rotations[0] = new Quaternion().fromAngleAxis((float) Math
            .toRadians(15), axisY);
      rotations[1] = new Quaternion().fromAngleAxis((float) Math
            .toRadians(30), axisY);
      rotations[2] = new Quaternion().fromAngleAxis((float) Math
            .toRadians(45), axisY);
      rotations[3] = new Quaternion().fromAngleAxis((float) Math
            .toRadians(60), axisY);
      rotations[4] = new Quaternion().fromAngleAxis((float) Math
            .toRadians(75), axisY);

      translations[0] = new Vector3f(0f, 0f, 0f);
      translations[1] = new Vector3f(0f, 0f, 0f);
      translations[2] = new Vector3f(0f, 0f, 0f);
      translations[3] = new Vector3f(0f, 0f, 0f);
      translations[4] = new Vector3f(0f, 0f, 0f);

      boneTrans.setBone(bone);
      boneTrans.setRotations(rotations);
      boneTrans.setTranslations(translations);

      float[] times = new float[5];
      times[0] = 0.3333f;
      times[1] = 0.6333f;
      times[2] = 0.9333f;
      times[3] = 1.3333f;
      times[4] = 1.6333f;

      boneAnim.addBoneTransforms(boneTrans);
      boneAnim.setInterpolate(true);
      int[] interpolations = { BoneAnimation.LINEAR, BoneAnimation.LINEAR,
            BoneAnimation.LINEAR, BoneAnimation.LINEAR,
            BoneAnimation.LINEAR };
      boneAnim.setInterpolationTypes(interpolations);
      boneAnim.setTimes(times);
      boneAnim.setEndFrame(4);

      ac.addAnimation(boneAnim);
      ac.setActiveAnimation(boneAnim);
      ac.setRepeatType(Controller.RT_CYCLE);

      bone.addController(ac);

   }

   @Override
   protected void simpleRender() {
      BoneDebugger.drawBones(rootNode, display.getRenderer(), true);
   }

   @Override
   protected void simpleUpdate() {
   }

   public static void main(String[] args) {
      TestBoneAnimation app = new TestBoneAnimation();
      app
            .setDialogBehaviour(AbstractGame.FIRSTRUN_OR_NOCONFIGFILE_SHOW_PROPS_DIALOG);
      app.start();
   }

}

You probably used the no-arg or String arg constructor.  If you use AxisRods(String name, boolean rightHanded, float baseScale), this won't happen.  I'll fix the String arg constructor.

Strange situation! Eclipse did not give me the other constructors options in the autocompletion men

Hmm, odd.  But, according to CVS, the one and only version of the file has all three constructors.

I am sorry. Maybe I have not seen it. I tryed today and third constructor appeared. XD