[SOLVED] Peculiar null pointer exception

So doing something completely unrelated to billboard controls appears to have crashed the app as seen here:

  SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
    java.lang.NullPointerException
    	at com.jme3.scene.control.BillboardControl.rotateScreenAligned(BillboardControl.java:197)
    	at com.jme3.scene.control.BillboardControl.rotateBillboard(BillboardControl.java:133)
    	at com.jme3.scene.control.BillboardControl.controlRender(BillboardControl.java:103)
    	at com.jme3.scene.control.AbstractControl.render(AbstractControl.java:119)
    	at com.jme3.scene.Spatial.runControlRender(Spatial.java:590)
    	at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:655)
    	at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:665)
    	at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:665)
    	at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:665)
    	at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:665)
    	at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:665)
    	at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:665)
    	at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:665)
    	at com.jme3.renderer.RenderManager.renderScene(RenderManager.java:640)
    	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:974)
    	at com.jme3.renderer.RenderManager.render(RenderManager.java:1029)
    	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:252)
    	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
    	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
    	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
    	at java.lang.Thread.run(Unknown Source)

I’ve looked into BillboardControl,java and it seems to break on this conditional:

    if ( parent != null ) { //line 197
        rot =  parent.getWorldRotation().inverse().multLocal(rot);
        rot.normalizeLocal();
    }

This one doesn’t make any sense since it’s a null check and that can’t possibly give a null pointer exception since that’s the whole point of it, right?

Here:

private void rotateBillboard(Camera cam) {
    switch (alignment) {
        case AxialY:
            rotateAxial(cam, Vector3f.UNIT_Y);
            break;
        case AxialZ:
            rotateAxial(cam, Vector3f.UNIT_Z);
            break;
        case Screen:
            rotateScreenAligned(cam); //line 133
            break;
        case Camera:
            rotateCameraAligned(cam);
            break;
    }
}

And here:

@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
    Camera cam = vp.getCamera();
    rotateBillboard(cam); //line 103
}

So, did I manage to somehow delete the camera or something? How would that happen, as I sure don’t remember doing any cam = null or simmilar.

I’d say you have a Version Mismatch (e.g. running 3.0 but looking into alpha-2 code).
However good that you came up with it since the Billboard needs some love anyway.

Here’s what I found back then.
I’ll search for what I finally had back then however since I couldn’t build up a decent Test Case I could never ensure it fully works.

So we could fix two bugs at once :slight_smile:

What you say appears to be right, I was looking at something from 2012 :smile:

After finding the latest one (is this the correct one now?), there doesn’t seem to be much of a difference. I’ll update the OP.

Well the problem is that 3.0 is no longer being maintained, I’m not sure if you can actually modify it anymore.

I can’t make a test case either since I have absolutely no idea which part of my code causes this. It just appears out of nowhere.

Line 197 on master:

So either getWorldRotation(), or inverse() return null.
Could you possibly print out the worldRotation Matrix?
If it isn’t null (possibly due to you modifiying it or not updating the geometric state), then it could be we have an error in inverting Matrices.

Anyway, sound’s like fun to fix :smiley: I’ve heard @nehon absolutely loves doing Math :stuck_out_tongue:

PS: I don’t get what you mean with “modify 3.0”? Are you running 3.0? (In that case my code snippet could be wrong again :stuck_out_tongue: ).
And with Test Case I mean the BBControl in General as it didn’t rotate correctly I think, however my test case: A rotating quad and a fixed camera wasn’t enough it seems.

Well it happens 100% of the time so I’m sure it’s not a multithreading thing, and the matrices cannot possibly be wrong as that would have shown up ages ago by everything breaking everywhere, no?

Math. Not even once.

I’m on 3.0, but I checked the sources that come with the distribution and the snippet is correct. This makes it even more bizzare.

You can’t tell that without simply checking it.
What means 100% of the time? As in you can’t launch your game anymore? So what triggered that issue?

Anyway such an error is always possible: If the rotation would be a bit off nobody would see it however you could have an edge case such as division by zero or w/e went wrong there.
So just show us the WorldRotation, I guess it’s null, but if not, it’ll be fun to see the inverse :confused:

Well since it’s only one line difference it could always be some misinterpreted newline or whatever happened there but it’s definately the second line then.

It happens every time a ship’s number of modules becomes zero, which is sort of irrelevant info as the billboards shouldn’t be affected at all, since they don’t have anything do do with it and aren’t attached to it. This appears to only trigger the real cause which I have no idea what it could be.
I’m sure that that doesn’t break anything on my end otherwise, because I just tesed by removing every use of billboards.

It’s not null, just some value it happens to be and the inverse seems good too.

WorldRotation: (0.09257431, 0.70821387, 0.08815635, 0.69432825)
Inverse: (-0.092574306, -0.7082138, -0.08815634, 0.6943282)

Edit: Hold on a minute I think i might have something.

Edit 2: Nevermind.

If that line is throwing a null pointer exception then one of:

  • parent is null
  • getWorldRotation() is returning null
  • inverse() is returning null

It cannot be otherwise. CANNOT. Just not possible.

So either that’s not really the line… or one of those things is throwing an NPE.

Print each value to confirm.

“But they shouldn’t be null.”

Well, yes, but one of them is.

Print each value to System.out.println()… recompile JME… run again. Dump your printlns here.

Edit:
Print each value IN THAT METHOD. Not in your code.

Show us the code you changed.

Or just copy the source to a custom class? Much less effort imo.

Edit:

I got this:

null (SimplePlasma) // not really null just no name, is a SimplePlasma module
(NaN, NaN, NaN, NaN)
null

From:

    if ( parent != null ) {
    	System.out.println(parent);
    	System.out.println(parent.getWorldRotation());
    	System.out.println(parent.getWorldRotation().inverse());
    	System.out.println(parent.getWorldRotation().inverse().multLocal(rot));
    	System.out.println("end");
        rot =  parent.getWorldRotation().inverse().multLocal(rot);
        rot.normalizeLocal();
    }

Yes, well… don’t set invalid rotations to your spatials I guess. :slight_smile:

Very funny.
You know when I check it anywhere else it’s not NaN. Still, one stop closer to figuring this out.

One question, could it be NaN because it’s not on the scene graph?

but the the spatial with the control attached that is causing the problem is detached from the scene graph at the moment of the crash. Why does the control even run then?

If this is the case, you’re in big trouble then. A Multitasking Issue isn’t that unrealistic then, it seems :confused: Good Luck anyway!

Another idea: Since you’ve already copied the code of the Billboard control:
Check every place where we’re setting rotations. Maybe you find the error there.

I’m pretty sure there’s a larger problem since I’ve noticed all other ships dissapear when yours looses all modules. Most likely physics spazzing out because of reverse movement to keep player at origin when suddently player’s mass is 0.

Not completely accurate then. :stuck_out_tongue:

Physics tend to set invalid rotations, yes!
Especially when their Velocitys are being set invalidly.

Note: Setting mass to 0 sounds also wrong. It’s not possible in the real world.
And when you want to make it solid ensure you create a new RigidBodyControl (or w/e) for this purpose

Of course it is. Do photons have mass? Do quarks have mass? Does a vacuum have mass? Because currently the ship has 0 stuff on it therfore 0 mass. :smile:

Can confirm, speed is NaN. :stuck_out_tongue: Although ingame, rotations get messed up a frame before velocity is.

Don’t worry I’ll find a workaround now that I know what’s actually wrong.

Okay, it doesn’t work in the physics engine world :stuck_out_tongue:
For example: applyForce -> 180N
a = F / m => a = Float.NaN or a = Float.INFINITY
I don’t know which would acctually happen on a DIV BY ZERO

Doesn’t your ship have a default mass? As in the ECU’s weight being 10kg or something. It could even be 1 / 10^121238 but > 0

Adding a default mass doesn’t have any effect, so apparently the problem is elswhere.

There is another weird thing though. This only affects ships and not other physics objects. Free floating modules are uneffected.

That was meant as the enemy ship speed (not the player speed). The player is actually fine, only the ships become NaNed up for some reason.

Weird… because 0 mass will definitely cause the exact sort of problems you are seeing. Physics rarely deals with math and deals with 1/mass instead. So mass = 0 in a physics engine will NaN everything that’s ‘integrated’ (the math term) as part of the physics loop.

Unless JBullet knows how to handle it, remember?

Bullet considers passing a mass of zero equivalent to making a body with infinite mass - it is immovable.

It makes the objects kinematic.

Pretty sure that:
http://javadoc.jmonkeyengine.org/com/jme3/bullet/control/RigidBodyControl.html#setKinematicSpatial(boolean)
…makes them kinematic. Then it’s valid to have a 0 mass.

Otherwise the physics engine will try to run physics for it and NaN everything.

I’ve never used bullet before so I could be wrong. But every physics engine I’ve ever used, (plus the one I wrote) will do bad things if you set mass = 0 to an object managed by physics then bad things will happen. Many physics engines supply a setter for inverse mass instead to avoid this issue. (inverseMass = 0 = static object)

But whatever… some setting is wrong somewhere if rotation ends up NaN. Setting mass to 0 is one of the things that will do that.