Skip to content

Commit 1bc444e

Browse files
committed
src/main/java/main/framework/Framework: stop the animator thread after user close the window
This change fixes the warning seen on Linux systems caused by system exit before JOGL have had the opportunity to properly closed the window after dispose. X11Util.Display: Shutdown (JVM shutdown: true, open (no close attempt): 2/2, reusable (open, marked uncloseable): 0, pending (open in creation order): 2) X11Util: Open X11 Display Connections: 2 X11Util: Open[0]: NamedX11Display[:0, 0x7f1f08004b30, refCount 1, unCloseable false] X11Util: Open[1]: NamedX11Display[:0, 0x7f1f08017c80, refCount 1, unCloseable false] Signed-off-by: Xerxes Rånby <xerxes@gudinna.com>
1 parent 6837c33 commit 1bc444e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/main/java/main/framework/Framework.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
import com.jogamp.newt.Display;
1010
import com.jogamp.newt.NewtFactory;
1111
import com.jogamp.newt.Screen;
12-
import com.jogamp.newt.event.KeyEvent;
13-
import com.jogamp.newt.event.KeyListener;
14-
import com.jogamp.newt.event.MouseEvent;
15-
import com.jogamp.newt.event.MouseListener;
12+
import com.jogamp.newt.event.*;
1613
import com.jogamp.newt.opengl.GLWindow;
1714
import com.jogamp.opengl.GL3;
1815
import com.jogamp.opengl.GLAutoDrawable;
@@ -81,6 +78,19 @@ private void initGL(String title) {
8178
animator = new Animator();
8279
animator.add(window);
8380
animator.start();
81+
82+
window.addWindowListener(new WindowAdapter() {
83+
@Override
84+
public void windowDestroyed(WindowEvent e) {
85+
new Thread(new Runnable() {
86+
public void run() {
87+
//stop the animator thread when user close the window
88+
animator.stop();
89+
System.exit(0);
90+
}
91+
}).start();
92+
}
93+
});
8494
}
8595

8696
@Override
@@ -122,7 +132,6 @@ protected void reshape(GL3 gl, int width, int height) {
122132

123133
@Override
124134
public final void dispose(GLAutoDrawable drawable) {
125-
126135
GL3 gl3 = drawable.getGL().getGL3();
127136

128137
end(gl3);
@@ -131,8 +140,6 @@ public final void dispose(GLAutoDrawable drawable) {
131140
BufferUtils.destroyDirectBuffer(clearDepth);
132141
BufferUtils.destroyDirectBuffer(matBuffer);
133142
BufferUtils.destroyDirectBuffer(vecBuffer);
134-
135-
System.exit(1);
136143
}
137144

138145
protected void end(GL3 gl) {

0 commit comments

Comments
 (0)