BillboardNode possible bug

Hello.

I'm using JMonkey 1. I have custom extension of BillboardNode, and it was repeteadly crashing with following error:


Nov 21, 2008 3:41:54 PM class com.funcom.tcg.client.TcgGame start()
SEVERE: Exception in game loop
java.lang.NullPointerException
   at com.jme.scene.BillboardNode.rotateCameraAligned(Unknown Source)
   at com.jme.scene.BillboardNode.rotateBillboard(Unknown Source)
   at com.jme.scene.BillboardNode.draw(Unknown Source)
   at com.jme.scene.Spatial.onDraw(Unknown Source)
   at com.jme.scene.Node.draw(Unknown Source)
   at com.jme.scene.Spatial.onDraw(Unknown Source)
   at com.jme.scene.Node.draw(Unknown Source)
   at com.jme.scene.Spatial.onDraw(Unknown Source)
   at com.jme.renderer.lwjgl.LWJGLRenderer.draw(Unknown Source)
   at com.funcom.tcg.token.TCGWorld.render(TCGWorld.java:92)
   at com.funcom.tcg.client.state.MainGameState.render(MainGameState.java:558)
   at com.jmex.game.state.GameStateNode.render(Unknown Source)
   at com.funcom.tcg.client.TcgGame.render(TcgGame.java:109)
   at com.jme.app.FixedFramerateGame.start(Unknown Source)
   at com.funcom.tcg.client.TcgJme.start(TcgJme.java:58)
   at com.funcom.tcg.client.TcgJme.main(TcgJme.java:69



After around half an hour of bashing the code and comparing my (relatively simple) extension to TestBillboardNode, I've found out what I was doing wrong:
The test was constructing billboard with a name, and I wasn't calling any super() in my subclass. Because default constructor super() is called during construction, my guess is that there is some initialization happening in I-have-name-parameter constructor that doesn't happen in default one. I add super("info-billboard") and it works.

I guess I don't have to write about how to fix it.

If this is fixed in 2.0, ignore the post, as we're upgrading soon.

Sincerely.

P.S. Sorry if anyone else posted this as a bug, I did a search, but mostly just glanced on the results...

this can also happen in jme 2.



The default constructor without parameter does nothing at all.


    public BillboardNode() {}

    public BillboardNode(String name) {
        super(name);
        orient = new Matrix3f();
        look = new Vector3f();
        left = new Vector3f();
        alignment = SCREEN_ALIGNED;
    }



your NPE happend in the rotateCameraAligned() Method, which uses the 'look' variable, which is of course null.

I guess the default constructor shouldn't be used at all.

The default constructor is to be used only for serialization. End-users should not use the empty constructor at all.

Momoko_Fan said:

The default constructor is to be used only for serialization. End-users should not use the empty constructor at all.


Oh... had no clue. Could you maybe put that in javadoc?