Search code examples
joglnativewindow

How do you close a JOGL/NEWT GLWindow completely?


I have an incredibly dumb little sample, probably ripped straight from a tutorial, every time it runs it generates warnings on exit. I'm curious what I'm missing. Any ideas, links, things I'm forgetting?

Here's the main window setup...

package com.emarcotte;

import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;

import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.util.FPSAnimator;

public class Main2 {
    public static void main(String[] args) {
        final RenderLoop loop = new RenderLoop();
        GLProfile glp = GLProfile.get(new String[] { GLProfile.GL3 }, true);
        GLCapabilities caps = new GLCapabilities(glp);
        GLWindow window = GLWindow.create(caps);
        window.setSize(300, 300);
        window.setVisible(true);
        window.setTitle("NEWT Window Test");
        window.addGLEventListener(loop);
        window.setAnimator(new FPSAnimator(window, 120));
        window.getAnimator().start();
        window.addWindowListener(new WindowAdapter() {
            @Override public void windowResized(WindowEvent we) {
                loop.setHeight(window.getHeight());
                loop.setWidth(window.getWidth());
            }
        });

        window.addKeyListener(new KeyAdapter() {
            @Override public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                    window.getAnimator().stop();
                }
            }
        });
    }
}

here are the warnings:

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.0, 0x7f214c0012b0, refCount 1, unCloseable false]
X11Util: Open[1]: NamedX11Display[:0.0, 0x7f214c017390, refCount 1, unCloseable false]

Solution

  • Call GLWindow.destroy() to close your NEWT GLWindow: http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/newt/opengl/GLWindow.html#destroy%28%29