Login  Register

NPE when getting GLDrawableFactory

Posted by François Coupal on Jan 17, 2011; 10:15pm
URL: https://forum.jogamp.org/NPE-when-getting-GLDrawableFactory-tp2276026.html

Well, hello again JOGL community. I'm trying to make a little test case working, and I'm a bit stumped.

Rapidly, the test tries to list all availiable graphic card extensions using a AWT rendering context. It's actually a very, very stripped down test case in a much larger project, but on it's own it's quite informative and while it looks simple, I'm getting a NPE (NullPointerException) in the GLCanvas class.

I figure it's not supposed to happen, but I'm also curious to know if there is a better way to quickly and dirtily get the extensions list.

Here is the unit test code:

*******

import java.util.Collections;
import java.util.SortedSet;
import java.util.TreeSet;

import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.opengl.DefaultGLCapabilitiesChooser;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLCapabilitiesChooser;
import javax.media.opengl.GLCapabilitiesImmutable;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLPbuffer;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;

public class testJOGL2 {
        public static void main(String[] args) {
                GLProfile.initSingleton(true);
                GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
                GLCanvas glc = new GLCanvas(caps);
                GLDrawableFactory usine = glc.getFactory();
                GLCapabilitiesImmutable glci = glc.getChosenGLCapabilities();
                GLCapabilitiesChooser glcc = new DefaultGLCapabilitiesChooser();
                AbstractGraphicsDevice agd = usine.getDefaultDevice();
               
                GLPbuffer pbuffer = usine.createGLPbuffer(agd, glci, glcc, 256, 256, null);
                GLContext context = pbuffer.getContext();
                context.makeCurrent();
                GL2 gl = pbuffer.getContext().getGL().getGL2();
               
                String extensions = gl.glGetString(GL.GL_EXTENSIONS);
                String[] tabExtensions = extensions.split(" ");
                SortedSet<String> setExtensions = new TreeSet<String>();
                Collections.addAll(setExtensions, tabExtensions);
                System.out.println(setExtensions);
        }
}

*********

Here is the console output:

Info: XInitThreads() called for concurrent Thread support
Exception in thread "main" java.lang.NullPointerException
        at javax.media.opengl.awt.GLCanvas.getFactory(GLCanvas.java:694)
        at testJOGL2.main(testJOGL2.java:24)

On a related note: is the first line some kind of common-loggings ou Log4J log output? How can I get rid of it?