Login  Register

Right method to exit/dispose on linux

Posted by elect on Feb 08, 2014; 10:30am
URL: https://forum.jogamp.org/Right-method-to-exit-dispose-on-linux-tp4031504.html

Hi,

playing with some tutorials on linux (Ubuntu 13.10 64b) I have problems in quitting my application

Here a small case

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ogldevtutorials.tutorial04;

import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.event.awt.AWTWindowAdapter;
import com.jogamp.newt.opengl.GLWindow;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;

/**
 *
 * @author elect
 */
public class Tutorial04 implements GLEventListener {

    public static void main(String[] args) {

        final Tutorial04 tutorial04 = new Tutorial04();

        final Frame frame = new Frame("Tutorial 04");

        frame.add(tutorial04.getNewtCanvasAWT());

        frame.setSize(tutorial04.getGlWindow().getWidth(), tutorial04.getGlWindow().getHeight());

        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent windowEvent) {
                tutorial04.getGlWindow().destroy();
                frame.dispose();
                System.exit(0);
            }
        });
//        frame.addWindowListener(new WindowAdapter() {
//            public void windowDestroyNotify(WindowEvent arg0) {
//                tutorial04.getGlWindow().destroy();
//                frame.dispose();
//                System.exit(0);
//            }
//        });

        frame.setVisible(true);
    }

    private GLWindow glWindow;
    private NewtCanvasAWT newtCanvasAWT;
    private int imageWidth;
    private int imageHeight;

    public Tutorial04() {

        imageWidth = 1024;
        imageHeight = 768;

        initGL();
    }

    private void initGL() {
        GLProfile gLProfile = GLProfile.getDefault();

        GLCapabilities gLCapabilities = new GLCapabilities(gLProfile);

        glWindow = GLWindow.create(gLCapabilities);

        newtCanvasAWT = new NewtCanvasAWT(glWindow);

        glWindow.setSize(imageWidth, imageHeight);

        glWindow.addGLEventListener(this);
    }

    @Override
    public void init(GLAutoDrawable glad) {
        System.out.println("init");

    }

    @Override
    public void dispose(GLAutoDrawable glad) {
        System.out.println("dispose");
    }

    @Override
    public void display(GLAutoDrawable glad) {
        System.out.println("display");
    }

    @Override
    public void reshape(GLAutoDrawable glad, int i, int i1, int i2, int i3) {
        System.out.println("reshape (" + i + ", " + i1 + ") (" + i2 + ", " + i3 + ")");
    }

    public NewtCanvasAWT getNewtCanvasAWT() {
        return newtCanvasAWT;
    }

    public GLWindow getGlWindow() {
        return glWindow;
    }
}


If I don't add any WindowListener then I can't close the window off course...

If inside the WindowClosing() I have only the System.exit(0) I get

X11Util.Display: Shutdown (JVM shutdown: true, open (no close attempt): 3/3, reusable (open, marked uncloseable): 0, pending (open in creation order): 3)
X11Util: Open X11 Display Connections: 3
X11Util: Open[0]: NamedX11Display[:0, 0x7fa5e84f99b0, refCount 1, unCloseable false]
X11Util: Open[1]: NamedX11Display[:0, 0x7fa5a40c9a70, refCount 1, unCloseable false]
X11Util: Open[2]: NamedX11Display[:0, 0x7fa5a40dd630, refCount 1, unCloseable false]


If I add frame.dispose(); I get a VM crash

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f9e25eb4736, pid=4400, tid=140317223712512
#
# JRE version: Java(TM) SE Runtime Environment (7.0_51-b13) (build 1.7.0_51-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libGL.so.1+0x87736]  glXCreateNewContext+0x4956
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/elect/Documents/oglDevTutorials/oglDevTutorials/hs_err_pid4400.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Java Result: 134


If I add the glWindow.dispose() nothing changes, still VM crash


So, how am I supposed to do it?

On windows I just do

frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent windowEvent) {
                System.exit(0);
            }
        });


Ps: I do not use animator ^^, please don't be angry with me for that :D