Login  Register

Crash when creating more than ~15 jogl/awt windows

Posted by GiGurra on Jun 12, 2011; 1:18am
URL: https://forum.jogamp.org/Crash-when-creating-more-than-15-jogl-awt-windows-tp3054540.html

Hi everyone,

I am new to this forum but not to jogl in general. Previously I used JOGL 1 for my current project but I am now in the process of trying JOGL 2.

I wish to run about 50+ windows in my current project (please don't ask why cause I couldn't tell you honestly, just want to let you know I need it and I am already running 150+ no problem utilizing c++ with direct3d)

A long time ago I ran into an issue where JOGL 1 refused to let me have more than about 40 awt windows with jogls GLCanvas inside if an animator was used - The application would simply lock up if I added more (this is regardless of system and java version, though some of my higher end machines can allow more windows before the crash than the lower end machines)

Today I thought I would give JOGL 2 a go and see if it would work, however the results were worse.
Making slight modifications to the simple jogl tutorial code found: http://jogamp.org/wiki/index.php/Using_JOGL_in_AWT_SWT_and_Swing
I created a very simple application (see source below) to test this out, and I'm only able to create about 15 windows before I start seeing lockups/freezes without any error messages. If I try to create more than 25 then i even get an exception in the console output (not just the ordinary lockups). I am using netbeans 7 and the -xmx1536m argument for the vm. Changing this doesn't change the test results.

Do you have any idea what might be causing this? Is it possible AWT and JOGL simply don't get along well?

"Exception in thread "main-AWTAnimator-1" javax.media.opengl.GLException: javax.media.opengl.GLException: Error making temp context current: 0x0x20013, werr: 0"........ (goes on many lines, tell me if I should paste everything)



/***** HelloJogl.java *****/

package hellojogl;

import com.jogamp.opengl.util.Animator;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;

public class HelloJogl {

    static {
        GLProfile.initSingleton(false);
    }

    public static void main(String[] args) {

        final GLProfile glprofile = GLProfile.getDefault();
        final GLCapabilities glcapabilities = new GLCapabilities(glprofile);

        final int numWindows = 15;
        final Animator animator = new Animator();
        for (int i = 0; i < numWindows; i++) {
            animator.add(new OneTriangleAWT(glprofile, glcapabilities).glcanvas);
        }

        animator.start();
    }
}


/********* OneTriangle.java ******/
package hellojogl;

import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;

public class OneTriangle {

    protected static void setup(GL2 gl2, int width, int height) {
        gl2.glMatrixMode(GL2.GL_PROJECTION);
        gl2.glLoadIdentity();
        GLU glu = new GLU();
        glu.gluOrtho2D(0.0f, width, 0.0f, height);
        gl2.glMatrixMode(GL2.GL_MODELVIEW);
        gl2.glLoadIdentity();
        gl2.glViewport(0, 0, width, height);
    }

    protected static void render(GL2 gl2, int width, int height) {
        gl2.glClear(GL.GL_COLOR_BUFFER_BIT);
        gl2.glLoadIdentity();
        gl2.glBegin(GL.GL_TRIANGLES);
        gl2.glColor3f(1, 0, 0);
        gl2.glVertex2f(0, 0);
        gl2.glColor3f(0, 1, 0);
        gl2.glVertex2f(width, 0);
        gl2.glColor3f(0, 0, 1);
        gl2.glVertex2f(width / 2, height);
        gl2.glEnd();
    }
}




/****** OneTriangleAWT.java *****/

package hellojogl;

import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.awt.GLCanvas;

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class OneTriangleAWT {

    final GLCanvas glcanvas;

    public OneTriangleAWT(final GLProfile glprofile, final GLCapabilities glcapabilities) {

        glcanvas = new GLCanvas(glcapabilities);
        glcanvas.addGLEventListener(new GLEventListener() {

            @Override
            public void reshape(GLAutoDrawable glautodrawable, int x, int y, int width, int height) {
                OneTriangle.setup(glautodrawable.getGL().getGL2(), width, height);
            }

            @Override
            public void init(GLAutoDrawable glautodrawable) {
            }

            @Override
            public void dispose(GLAutoDrawable glautodrawable) {
            }

            @Override
            public void display(GLAutoDrawable glautodrawable) {
                OneTriangle.render(glautodrawable.getGL().getGL2(), glautodrawable.getWidth(), glautodrawable.getHeight());
            }
        });

        final Frame frame = new Frame("One Triangle AWT");
        frame.add(glcanvas);
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent windowevent) {
                frame.remove(glcanvas);
                frame.dispose();
                System.exit(0);
            }
        });

        frame.setSize(640, 480);
        frame.setVisible(true);

    }
}