NullPointerException when ending Application with JMEDesktop

I made an application basing on BaseGame that utilizes JMEDesktop. It currently only contains one button and a label.



Normally, when I end the application (with the escape key), I dispatch the desktop and everything is fine. But if I end the program while the button has the focus, I get the following exception:


20.09.2006 10:50:19 com.jme.scene.Node detachChildAt
INFO: Child removed.
java.lang.NullPointerException
        at javax.swing.JComponent._paintImmediately(JComponent.java:4845)
        at javax.swing.JComponent.paintImmediately(JComponent.java:4666)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:451)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:114)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
In paintImmediately null graphics
20.09.2006 10:50:19 com.jme.app.BaseGame start
INFO: Application ending.


This doesn't happen in the TestJMEDesktop example, though. Is that because I extended BaseGame instead of SimpleGame? Any idea how to fix it?

Possibly you did not dispose the desktop? (see cleanup method in the test)

irrisor said:

Possibly you did not dispose the desktop? (see cleanup method in the test)

No, as written above, I did dispose the desktop.
I just tried not disposing the desktop, and actually, the exception isn't thrown then, but the program continues to run (because the desktop is still there).

Update:

I've worked around this by using a button, instead of escape, to quit my application. But it would be nice to know where I've had an error :wink:

err, did you use thread decoupling for that button (e.g. JMEAction)? If not it would explain why it behaves different. Try calling dispose in invokeAndWait and don't exit the application from the swing thread.

irrisor said:

err, did you use thread decoupling for that button (e.g. JMEAction)? If not it would explain why it behaves different. Try calling dispose in invokeAndWait and don't exit the application from the swing thread.

I don't use JMEAction, and I don't end the application from the swing thread.
The listener just sets the finished variable (which my application inherited from BaseGame) to true, and that's it.

Is this something that I shouldn't do?

no that's fine - what does ESC do different then?

irrisor said:

no that's fine - what does ESC do different then?

Well, nothing, actually.

I guess that pressing ESC sends an Event to the Desktop, which is processed only after the application ends. And this Event seems to make the button repaint itself (javax.swing.JComponent._paintImmediately()), but on an dispatched JDesktopPane on a non-existant display. A very wild guess, but the only that I could come up with.

Sound like a good explanation. I'll check that…

Keep in mind that it only happens when one of the buttons has the focus (it's visibly selected), and it doesn't happen in the demo.

I was not able to reproduce your problem. I committed a probable fix to CVS, though. Please test if it helps. If not please post an little example program.

irrisor said:

I was not able to reproduce your problem. I committed a probable fix to CVS, though. Please test if it helps. If not please post an little example program.

On the first few runs, it seems to work (the exception didn't occur every time anymore since I moved on to GameStates).

But there seems to be a little side-effect... I don't receive any calls to mouseDragged() in my MouseMotionListener anymore. (but I still receive them to mouseMoved()).
Unluckily, I'm not sure if this is a new error, because I've been using the .10 JME before.
It might be my fault, though, for just putting the new JMEDesktop and JMEDragAndDrop into .10... I REALLY hate being behind such a bitchy firewall / proxy combination.
I'll try to put the new JMEDesktop into the current nightly build.

Update: neither the combination nightly build - new JMEDesktop nor the nightly build 'as is' seem to like calling my mouseDragged().

I'm back on .10  :expressionless:

As posted in the other thread please check if it is caused by that patch mentioned there.

irrisor said:

As posted in the other thread please check if it is caused by that patch mentioned there.

It is, in fact, caused by that patch.