Spatial getWorldRotation() NaN?

I ran into some troubles while adding more stuff to my game.



It had been all dandy for some time, and while adjusting something completely

unrelated I started getting a nullpointer from one of my billboard controls attached to DamageTexts.



After debugging the client I concluded that the

[java]getParent().getWorldRotation()[/java]

had all values at “NaN”.



And the nullpointer occured when the billboard control attempted to align towards camera.



BillboardControl.java

[java]

private void rotateScreenAligned(Camera camera) {

// coopt diff for our in direction:

look.set(camera.getDirection()).negateLocal();

// coopt loc for our left direction:

left.set(camera.getLeft()).negateLocal();

orient.fromAxes(left, camera.getUp(), look);

Node parent = spatial.getParent();

Quaternion rot=new Quaternion().fromRotationMatrix(orient);

if ( parent != null ) {

rot = parent.getWorldRotation().inverse().multLocal(rot); // HERE

rot.normalizeLocal();

}

spatial.setLocalRotation(rot);

fixRefreshFlags();

}

[/java]



Considering the world rotation of the parent was at NaN, the inverse() of it would return a null object.

So overriding the controlRender I concluded that this was the cause of the nullpointer crash.



http://puu.sh/OYA0.png



[java]

bc = new BillboardControl() {

@Override

protected void controlRender(RenderManager rm, ViewPort vp) {

if (getParent() == null) {

System.out.println(“Parent null”);

return;

} else if (getParent().getWorldRotation().inverse() == null) {

System.out.println(“Parent world rotation null”);

return;

}

super.controlRender(rm, vp);

}

};

[/java]



The parent is not null.



However to my questions to you:

Why would the worldRotation be invalid?

Why is this happening randomly?

And also, it shows Player as parent, but I’m adding the BillboardControl to the DamageText, a sub node of the player node.

We don’t really get random messed up quaternions or wrong spatials on getParent so it must be in your code. Do you extend any classes? Override stuff? You know you’re not supposed to change the locations and rotations in controlRender, yes?

I’m extending nodes, but not overriding any methods.

Also I’m not changing any stuff in controlRender, the only reason I override it here was to debug/figure out what was throwing the nullpointer.

I should also say that this happens very occasionally.



The quickest way I can reproduce it is to spawn ~100 npcs,

shoot through them, spawning alot of damage texts (billboard control bitmaptext).

Eventually anywhere between 10 and 60 seconds, the nullpointer will pop up.



A thousand damage texts can be created and disposed in less than a minute.



Node structure of players is like this.

[java]

  • Players node
  • Player
  • DamageTexts node
  • DamageText
  • HealthBar
  • CharacterName

    [/java]



    I just cant figure out why world rotation at any time could be NaN, is there any way I could continue troubleshooting?



    Could it be NaN if it was not attached to any parent and not added to the rootNode?

Try breakpointing the variable for NaN going into it and then looking at the call stack?