Detect Window Closing

Hello,
I am new to using jMonkey and am running into a slight problem.

I have a shutdown method that I need run when the window is closed (i.e. the X button) to stop network communication and other threads. I am not finding a way to listen for the window closing. I understand that this is built on top of lwjgl which I am familiar with and that is has a way to listen for if the native window is closing.

Any help would be great.
Thanks!

1 Like

http://hub.jmonkeyengine.org/javadoc/com/jme3/app/state/AppState.html#cleanup()

1 Like
@tlf30 said: Hello, I am new to using jMonkey and am running into a slight problem.

I have a shutdown method that I need run when the window is closed (i.e. the X button) to stop network communication and other threads. I am not finding a way to listen for the window closing. I understand that this is built on top of lwjgl which I am familiar with and that is has a way to listen for if the native window is closing.

Any help would be great.
Thanks!

DO NEVER rely on this.
Cleaning your stuff up is fine, but if you get a sig9 or a process kill in windows your process will never reach that part.
So eg when using an embedded database make it so, that it can recover from ungracefull shutdowns.

1 Like
@Empire Phoenix said: DO NEVER rely on this. Cleaning your stuff up is fine, but if you get a sig9 or a process kill in windows your process will never reach that part. So eg when using an embedded database make it so, that it can recover from ungracefull shutdowns.

Of course, in that case the other threads and network communication (from the OP) are stopped anyway… but it is a good warning for services that might naively require proper shutdown in all cases.

1 Like