[RESOLVED] Android Exception unsure how to tackle

Hey guys. For our android game, I’ve taken to moving the files every now and then from our jME game to android studio with gradle, to properly enable multidex builds. It manages to build and run, which I’m am over the moon about. But I’m getting an exception I don’t know how to tackle:

10-15 11:45:21.091 26047-26210/elrel.velocityy_gradle E/com.jme3.app.AndroidHarnessFragment: SEVERE Exception thrown in Thread[GLThread 28786,5,main]
                                                                                             java.lang.NullPointerException: Attempt to invoke interface method 'void com.jme3.scene.control.Control.render(com.jme3.renderer.RenderManager, com.jme3.renderer.ViewPort)' on a null object reference
                                                                                                 at com.jme3.scene.Spatial.runControlRender(Spatial.java:756)
                                                                                                 at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:723)
                                                                                                 at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:733)

Any suggestions how to tackle this? It works on my PC, but the android version throws this. It doesn’t look like it comes from my code though.

Also, I haven’t imported all the jars I have in my PC build. I thought it would throw an error when compiling because it couldn’t find certain classes, but that doesn’t appear to be the case. Extra information, in case that helps.

public void runControlRender(RenderManager rm, ViewPort vp) {
        if (controls.isEmpty()) {
            return;
        }

        for (Control c : controls.getArray()) {
            c.render(rm, vp);
        }
    }

So the line c.render fails, which to me means: You somewhere called spatial.addControl(null);
Can you try to debug the Application so you could hover over controls or maybe get the Spatial Name?

The thing is, whilst addControl does not effectively check for a null pointer, it should crash if you supply a null control.

    public void addControl(Control control) {
        boolean before = requiresUpdates();
        controls.add(control);
        control.setSpatial(this);  

Maybe you catch this exception and the control stays in controls, though?
We could/should exchange the order so a faulty control doesn’t make it into controls but crashes in addControl, so you even have the stack trace to the root of the problem.

I’ll go ahead an try debugging each of my calls to addControl. But why does this work on PC, and not on android. If the source code is as you’ve shown, wouldn’t it fail on PC too?

EDIT: Also, in my app there is currently no exception handling. So I couldn’t possibly be doing that :slight_smile:

It might be that the android libraries return null in your specific scenario, you never know.
Without the root of the problem (i.e. which control or rather with spatial fails) it’s relatively hard to debug.

Alternatively you can try removing part by part to see when it is working again.

I got it, but it was rather weird.

I have a “scene” called rocket.j3o, which is a combination of a rocket, a flame, and a smoke model. The rocket and smoke models have, via the SceneComposer, a FlameControl and SmokeControl attached. These are the only controls I have attached this way. All others are instantiated and attached via code. The code barfs on the flame_drop node, which should have this FlameControl and SmokeControl in it’s child nodes. But somehow, the controls become null, throwing the render error.

Is there a way I can investigate this further to perhaps fix it? I’m not sure how I would analyze it though, considering it worked on PC just fine.

Thanks @Darkchaos

Maybe there is a bug with deserializing the controls in android?
I can’t image how but you never know.

You could provide us those controls or atleast look for this:
What happens when a control is loaded is that the cloneForSpatial method is called and maybe some new jmeClone method as well.

Are you sure that that particular method works reliable? Can you see something which could break on android?
Try setting a Breakpoint at those methods and see if they somehow return null.