Login  Register

NullPointerException on GLCanvas.dispose

Posted by Doug on Aug 18, 2010; 6:57pm
URL: https://forum.jogamp.org/NullPointerException-on-GLCanvas-dispose-tp1212161.html

I can't seem to cleanly close out an application with a GLCanvas embedded in a JFrame without an exception being thrown. The exception is a null pointer encountered during the GLCanvas.dispose() call. I'm running on Windows XP using Java 1.6_20 and a recent version of JOGL. Below is the stripped down code to generate the exception, and below that is the exception itself. Is anyone else seeing this problem? If so, any help would be appreciated. Thanks.

----------
import java.awt.BorderLayout;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.media.opengl.awt.GLCanvas;
import javax.swing.JFrame;

public class GLframe {
    protected JFrame jFrame = null;
    
    public static void main(String[] args) {
        new GLframe();
    }
    
    protected GLframe() {
        GLCanvas glCanvas = new GLCanvas();
        glCanvas.setSize(256, 256);
        jFrame = new JFrame();
        jFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        jFrame.setLayout(new BorderLayout());
        jFrame.getContentPane().add(glCanvas, BorderLayout.CENTER);
        jFrame.addWindowListener(new WindowHandler());
        jFrame.pack();
        jFrame.setVisible(true);
    }
    
    private final void close() {
        jFrame.dispose();
    }
    
    private final class WindowHandler implements WindowListener {
        public final void windowOpened(WindowEvent windowEvent) {
            System.out.println("windowOpened");
        }
        public final void windowClosing(WindowEvent windowEvent) {
            System.out.println("windowClosing");
            close();
        }
        public final void windowClosed(WindowEvent windowEvent) {
            System.out.println("windowClosed");
        }
        public final void windowIconified(WindowEvent windowEvent) {}
        public final void windowDeiconified(WindowEvent windowEvent) {}
        public final void windowActivated(WindowEvent windowEvent) {}
        public final void windowDeactivated(WindowEvent windowEvent) {}
    }
}
----------
windowOpened
windowClosing
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at javax.media.opengl.awt.GLCanvas.dispose(GLCanvas.java:336)
	at javax.media.opengl.awt.GLCanvas.removeNotify(GLCanvas.java:452)
	at javax.media.opengl.awt.GLCanvas.destroy(GLCanvas.java:349)
	at javax.media.opengl.awt.GLCanvas$2.destroyMethod(GLCanvas.java:307)
	at javax.media.opengl.awt.GLCanvas$1.windowClosing(GLCanvas.java:165)
	at java.awt.AWTEventMulticaster.windowClosing(AWTEventMulticaster.java:333)
	at java.awt.Window.processWindowEvent(Window.java:1865)
	at javax.swing.JFrame.processWindowEvent(JFrame.java:274)
	at java.awt.Window.processEvent(Window.java:1823)
	at java.awt.Component.dispatchEventImpl(Component.java:4630)
	at java.awt.Container.dispatchEventImpl(Container.java:2099)
	at java.awt.Window.dispatchEventImpl(Window.java:2478)
	at java.awt.Component.dispatchEvent(Component.java:4460)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
windowClosed
----------