Programm exit?


I got the problem that my JME program doesn't shutdown itself…

I'm using a StandardGame with Gamestates, but closing the application with the X in the windowed mode it doesn't close itself.

Only with a press on Escape. Then I had a look on the debuggamestate and i saw it only calls System.exit(0);

But where do I have to register the Window Handler on the graphics window?

Haven't found anything…



There have been some threads on closing StandardGame.

Here is one

And here is some discussion from the middle of a thread.

However these deal more with how to shut down your StandardGame cleanly. However the problem you described (program not closing when pressing X) sounds quite unique for me - closes my app. every time and i am also using Standard and Gamestates…

Hopefully you will find some help with your problem from the threads posted…

The window stays open after clicking "X"?  That's very odd…I have never seen that one either.  I believe that would technically have to be a bug in LWJGL since that is what creates and maintains that window.

no, the window is closed after the x, but the application keeps running…

the click doesn't shutdown the whole app, only the window is closed.

Right… some thread keeps running… I get that occasionally now that I am playing with JGN… What fixed it for me was having a nice shutdown function that I call that in turn calls game.shutdown() on both my StandardGames and then System.exit()… but i guess t is not completely clean either…

I tried calling shutdowns on JGN threads also… but that did not quite work out for me, so I am neglegting them for now… I guess I will be haunting the forums with a similar thread at some point in the future :slight_smile:

That's odd…JGN doesn't kick of any threads itself, you explicitly define every thread it creates.  However, there are the JGN.createThread / JGN.createRunnable convenience methods, but if you make sure to shutdown all your servers it should cleanly terminate just fine.

You need to make all your threads daemon (Thread.setDaemon), except for the render thread, then your application should shut down when the render thread shuts down. If you're using AWT/Swing, you need to call dispose on all your created windows, setVisible(false) is not enough I think.

JGN.createThread does not, and will not do that.  You can setDaemon(true) on it after it is created if you like, but because JGN may be used apart from any other defined game aspects setting it to daemon may cause the application to simply stop running because no other threads are blocking termination.  Besides, daemon threads are not always a good idea, particularly if there is cleanup that should be done before termination.  This is why there is a shutdown methodology instead.

Hey - this thread hasn't been touched in a while…but I was curious if there was ever a resolution?  I am experiencing the same issue, except only in certain circumstances.

When I run from Eclipse, there is no problem.  I hit the exit button and it works fine - program terminates.  Its when I deploy via web start that it fails to exit.  It sticks around as a running process taking up about 60 megs of memory.  My buddy tried running the application a few times (exitting via the button each time) and performance quickly got worse.

So, I'm not sure why it wouldn't work in web start, but works fine from the IDE?  No code differences between the two…

This seems to be a major problem with JME, shutting down. There have been many threads about this, not specifically this, but other ways too.

So do we have any idea what causes it?  Could we add some sort of callback into standard game so that if the GL window dies then the standard game dies too?  Is there some sort of monitoring we could do?

Has anyone found a work around?


try to see what kind of threads are still running after you close the application.

i think the opengl thread should automatically die when all other died.

Easiest fix is just to call System.exit(0) at the end, however, this is not a jME issue, nor is it a JGN issue, but rather a problem with some thread hanging on after you finish running.  I had problems previously with this and the culprit ended up being the extra threads that Substance L&F creates that were not dying properly.  StandardGame will die properly when the application is terminated, but non-daemon threads may stay running unless you do a System.exit(0);

Is there something you can set (like in JFrame) as to the default close operation?  Like with JFrame you can tell it to continue running or exit the system.

If there was some way I could tell that the user clicked the X button on the window…then it would be easy for me to call System.exit(0)

thorst said:

If there was some way I could tell that the user clicked the X button on the window...then it would be easy for me to call System.exit(0)

There is a way.

You can't use WindowListener for native windows. LWJGL provides a method Display.isCloseRequested which tells if the user pressed the X button, or Alt-F4 on the window.

Since jME abstracts us away from LWJGL (and since it appears we're switching to JOGL?) does jME provide a hook that uses that LWJGL method to determine if a native window is closed?  If not - what would the impacts be to provide that hook?  We could probably request it via the Contribution Depot…

Momoko_Fan said:

You can't use WindowListener for native windows. LWJGL provides a method Display.isCloseRequested which tells if the user pressed the X button, or Alt-F4 on the window.

Yes, of course. Wasn't thinking that through.

The thread preventing JMe to shutdown on my side is AWTEventHandler and is not controlled/coded by me. Is there a way to catch when jme close so that I can do a System.Exit() to end that thread?

Found something! I override cleanup in the gamestate:

    public void cleanup() {