开发者

Gracefully shutting down a Java OpenGL (JOGL) app

开发者 https://www.devze.com 2023-01-04 03:43 出处:网络
I have an application with a JOGL component. When it shuts down using System.exit(0), I frequently get the exception:

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(Referenc开发者_运维知识库eQueue.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.


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);
}


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号