Jeff Storey
Jeff Storey

Reputation: 57202

Gracefully shutting down a Java OpenGL (JOGL) app

I have an application with a JOGL component. When it shuts down using System.exit(0), I frequently get the exception:

java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134)
at sun.java2d.Disposer.run(Disposer.java:125)
at java.lang.Thread.run(Thread.java:619)

I have seen this question Occasional InterruptedException when quitting a Swing application but I don't have any non-daemon threads running. I'm wondering if the underlying JOGL code is continuously putting events in the swing event queue which could cause this error since the swing app will only shutdown properly when the event queue is empty.

Is there a way to shutdown more cleanly? Maybe somehow stop the JOGL main loop (I'm using a 3rd party tool, nasa worldwind, so I don't necessarily have access to the main Animator running the app).

EDIT: It turns out this was not an openGL problem at all. OpenGL was being properly shutdown and there was just a race in a shutdown hook I had running. Thanks.

Upvotes: 2

Views: 1891

Answers (3)

Jeff Storey
Jeff Storey

Reputation: 57202

It turns out this was not an openGL problem at all. OpenGL was being properly shutdown and there was just a race in a shutdown hook I had running. Thanks.

Upvotes: 0

slf
slf

Reputation: 22777

From JOGL wiki page

import java.awt.Frame;
import com.sun.opengl.util.Animator;

// ...

frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            exit();
        }
        });

// ...

public static void exit(){
    animator.stop();
    frame.dispose();
    System.exit(0);
}

Upvotes: 3

Nikolaus Gradwohl
Nikolaus Gradwohl

Reputation: 20124

make sure you stop everything you started before calling System.exit();

if you start an animator using

Animator anim = new Animator(canvas); anim.start();

be sure to call anim.stop() before you exit your program

Upvotes: 2

Related Questions