Bug on disposal (InputHandler bug)

When I dispose of a JMEDesktop that has input set to null I get an error.



Exception in thread "main" java.lang.NullPointerException

at com.jme.input.InputHandler.removeAllActions(Unknown Source)

at com.jmex.awt.swingui.JMEDesktop.dispose(Unknown Source)

at imp.ingame.ship.cockpit.GlassScreen.disposeAll(GlassScreen.java:155)

at imp.Imp.cleanup(Imp.java:207)

at com.jme.app.VariableTimestepGame.start(Unknown Source)

at imp.Imp.main(Imp.java:118)



Line 1241 in JMEDesktop could use an inputHandler != null check.

The question is: why is it null? It is initialized with a new InputHandler() and it is final… You should compile with debug info to see the actual problematic line.

Sorry, I've been away from the code for a week. Well to answer your question, it's null because I set it up that when on creation. I just want desktops with no input because I'm using them as displays only.

So you altered the source of JMEDesktop? If yes, I can't do much about it. If no, I still say, that the NPE must be caused by something else, so please post a full stacktrace (with line numbers).

Heh, no I didn't touch the JMEDesktop code. I just pass in a null to the constructor for the input handler parameter and then the bug appears when I dispose of it when my application closes.

Well I'm using JME from the jar, so that's why there are no line numbers above and yeah I know, it makes this difficult to debug.



But here's what I think is the problem. In InputHandler under the removeAllActions method, there is no check to see if allTriggers is null. The checking exists in other methods in the class (although a bit spotty), but not here.




I had the same problem, I didn't knew where the exception came from and toke me a great deal of time to find it.

I would appreciate if something was in the javadoc, or you made a simple check in the constructure, like


if (input = null)
  input = new InputHandler....


This would have saved me from lot of time wasting, and will defiantly help lot others too.

Teaster

That won’t help - inputHandler is never null. But I took a look at the exception now: I think you both just misinterpreted it :-o - it’s not the inputHandler that was null but something in the InputHandler! Most likely the triggers list was null - this does not happen any more. Please check if your problems still exists with the current CVS versino (was fixed a week ago).

irrisor said:

That won't help - inputHandler is never null. But I took a look at the exception now: I think you both just misinterpreted it :-o - it's not the inputHandler that was null but something in the InputHandler! Most likely the triggers list was null - this does not happen any more. Please check if your problems still exists with the current CVS versino (was fixed a week ago).
It is more a mistake than a bug, but it is a very annoying mistake.
what I did was:
new JMEDesktop( String name, final int width, final int height, InputHandler inputHandlerParent );
and as the inputHandlerParent I put null, that made a very strange null pointer exception which was very thought to find.

I find it would be good for a checking against.

Teaster

passing inputHandlerParent==null is fine for JMEDesktop as well, it cannot cause any NPE (really!)