Posted by
Sven Gothel on
Sep 21, 2012; 6:35am
URL: https://forum.jogamp.org/JVM-Crash-During-X11-Shutdown-tp4026218p4026231.html
On 09/21/2012 12:25 AM, rhatcher [via jogamp] wrote:
> This begs another question though:
>
> I assume the shutdown responsibility of well-behaved JOGL graphics components
> is to implement "dispose" and make sure everything is cleaned up there,
We are talking about AWT, I see :) .. YES
> but
> the responsibility for calling dispose lies elsewhere.
>
> I experimented with this some in a small test app and it looked like dispose
> won't get called unless either the frame containing the GLCanvas is disposed
> explicitly or the canvas itself is disposed explicitly (?). IOW unless I had
> a window listener like this:
>
> private class TestWindowAdapter extends WindowAdapter
> {
> @Override
> public void windowClosing( WindowEvent e )
> {
> new Thread( new Runnable() {
> public void run() {
> _animator.stop() ;
> _graphicsFrame.dispose() ;
> System.exit(0) ;
> }
> } ).start() ;
> }
> }
>
> ...and a File->Quit handler like this:
>
> quitMenuItem.addActionListener( new ActionListener() {
> public void actionPerformed( ActionEvent event ) {
> new Thread( new Runnable() {
> public void run() {
> _animator.stop() ;
> _graphicsFrame.dispose() ;
> System.exit(0) ;
> }
> } ).start() ;
> }
> } ) ;
>
1) Don't do it in another thread @ windowClosing, it's too late
2) Don't call System.exit(0) ..
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Swing JFrame only (I guess)
// close nicely w/ GLCanvas destruction
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
getContentPane().remove(fCanvas); // Swing JFrame !
remove(fCanvas); // AWT Frame !
}
});
Then it should work ..
> ...i.e. that called _graphicsFrame.dispose() explicitly, then dispose() in my
> GLEventListener didn't get called, and I still got the crash.
>
> So, even if the various listeners implement dispose() this cleanup is not
> exactly automatic and some careful setup is required to make sure it happens.
>
> I ran the Gears/JGears demo and it crashed at shutdown too (and the Gears
> dispose method didn't get called) until I added an explicit dispose call on
> the frame.
It's possible that we haven't added nice shutdown there .. :)
Will look into the Gears* demos _in_ the unit tests.
Ping you back when done.
~Sven