Newt window quit silently on Mac OS X 10.9

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

Newt window quit silently on Mac OS X 10.9

Jikid
Hello
This code snippet is copied from Justin's JOGL Tutorial, the window shows up, but quit automatically after a few second.
My Laptop: Mac OS X 10.9 + jogl 2.1.2
Is the display() has to be called repeatedly to prevent the window from closing? Thank you!

import javax.media.opengl.*;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;

public class SimpleScene {
    public static void main(String[] args) {
        GLProfile glp = GLProfile.getDefault();
        GLCapabilities caps = new GLCapabilities(glp);

        GLWindow window = GLWindow.create(caps);
        window.setSize(300, 300);
        window.setVisible(true);
        window.setTitle("NEWT Window Test");

        window.addWindowListener(new WindowAdapter() {
            public void windowDestroyNotify(WindowEvent arg0) {
                System.exit(0);
            };
        });
    }
}
Reply | Threaded
Open this post in threaded view
|

Newt window quit silently on Mac OS X 10.9

Jikid
Hello
This code snippet is copied from Justin's JOGL Tutorial, the window shows up, but quit automatically after a few second.
My Laptop: Mac OS X 10.9 + jogl 2.1.2
Is the display() has to be called repeatedly to prevent the window from closing? Thank you!

import javax.media.opengl.*;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;

public class SimpleScene {
    public static void main(String[] args) {
        GLProfile glp = GLProfile.getDefault();
        GLCapabilities caps = new GLCapabilities(glp);

        GLWindow window = GLWindow.create(caps);
        window.setSize(300, 300);
        window.setVisible(true);
        window.setTitle("NEWT Window Test");

        window.addWindowListener(new WindowAdapter() {
            public void windowDestroyNotify(WindowEvent arg0) {
                System.exit(0);
            };
        });
    }
}
Reply | Threaded
Open this post in threaded view
|

Re: Newt window quit silently on Mac OS X 10.9

jmaasing
In reply to this post by Jikid
I have the same on my OSX 10.9 - I don't know why. Maybe since the main thread exits there is nothing driving the events and the window closes since the main thread exits.
Anyway, this is the skeleton I use to drive my clients, hope that helps.

public static void main(String[] args) {
                GLProfile glp = GLProfile.getDefault();
                GLCapabilities caps = new GLCapabilities(glp);

                GLWindow window = GLWindow.create(caps);
                window.setSize(300, 300);
                window.setVisible(true);
                window.setTitle("NEWT Window Test");
                final Animator animator = new Animator(window);

                window.addWindowListener(new WindowAdapter() {
                        @Override
                        public void windowDestroyNotify(WindowEvent arg0) {
                                animator.stop() ;
                        }
                ;
                });
                window.addGLEventListener(new GLEventListener() {

                        @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");
                        }
                });
                animator.start();
        }
Reply | Threaded
Open this post in threaded view
|

Re: Newt window quit silently on Mac OS X 10.9

Sven Gothel
Administrator
On 12/01/2013 12:17 PM, jmaasing [via jogamp] wrote:
> I have the same on my OSX 10.9 - I don't know why. Maybe since the main thread
> exits there is nothing driving the events and the window closes since the main
> thread exits.

This is correct!

> Anyway, this is the skeleton I use to drive my clients, hope that helps.

Your code uses an Animator, which uses a non daemon thread
as described in it's API doc.
Hence it will uphold the JVM from exit.

I assume your code works as expected, i.e. the JVM
only exists when you close the window.

The other example w/o Animator will exit the JVM immediately
on _all_ platforms.
If the user desires not to use an animator, one needs
to prevent the main thread from exiting until the window is being closed.

This behavior is a design decision.

~Sven




signature.asc (911 bytes) Download Attachment