NullPointerException on GLCanvas.dispose

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

NullPointerException on GLCanvas.dispose

Doug
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
----------
Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException on GLCanvas.dispose

Doug
Not even a hint?
Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException on GLCanvas.dispose

Pedro
Hi all,
I've got the same issue
Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException on GLCanvas.dispose

gouessej
Administrator
In reply to this post by Doug
Don't call dispose when closing the window as it has already been called while closing it.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException on GLCanvas.dispose

Wade Walker
Administrator
Is it really that simple? It looks like when you specify JFrame.DO_NOTHING_ON_CLOSE, you're supposed to dispose the window in the windowClosing event (see here). Maybe the GLCanvas doesn't respect the DO_NOTHING_ON_CLOSE properly?
Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException on GLCanvas.dispose

Sven Gothel
Administrator
On Monday, December 20, 2010 23:52:35 Wade Walker [via jogamp] wrote:
>
> Is it really that simple? It looks like when you specify JFrame.DO_NOTHING_ON_CLOSE, you're supposed to dispose the window in the windowClosing event (see here ). Maybe the GLCanvas doesn't respect the DO_NOTHING_ON_CLOSE properly?
>

yup ..

already checked in .. but have to refine the unit tests

~Sven
Reply | Threaded
Open this post in threaded view
|

Re: NullPointerException on GLCanvas.dispose

gouessej
Administrator
In reply to this post by Wade Walker
On my view, dispose() is already called in windowClosing() even though you specify JFrame.DO_NOTHING_ON_CLOSE.
Julien Gouesse | Personal blog | Website