Login  Register

Re: NPE when getting GLDrawableFactory

Posted by François Coupal on Mar 07, 2011; 3:18pm
URL: https://forum.jogamp.org/NPE-when-getting-GLDrawableFactory-tp2276026p2646518.html

Warning, long post because of code snippets and error messages

Here is a JUnit test case for recreating the NPE problem. As you can see, it does not even try to use a Frame even though it uses a GLCanvas (In the following post I will put up some code that will).

It breaks at the seventh line in the main method. An NPE is thrown. This code breaks using the RC2 and build 341 JOGL libraries (on Ubuntu Linux). Following is the error messages when executed (with build 341) as an application, not as a unit test.

*************

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;

import org.junit.Test;

public class testJOGL2 {

        public static void main(String[] args) {
                testJOGL2 instance = new testJOGL2();
                instance.testJogl2ExtensionCheck();
        }

        @Test
        public void testJogl2ExtensionCheck() {
                GLProfile.initSingleton(false);
// GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
                GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
                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);
        }
}

************************

java.lang.Throwable: main - Info: NativeWindowFactory.<init>
        at javax.media.nativewindow.NativeWindowFactory.<clinit>(NativeWindowFactory.java:119)
        at javax.media.opengl.GLProfile.initProfilesForDefaultDevices(GLProfile.java:1164)
        at javax.media.opengl.GLProfile.access$000(GLProfile.java:71)
        at javax.media.opengl.GLProfile$1.run(GLProfile.java:117)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.media.opengl.GLProfile.initSingleton(GLProfile.java:115)
        at testJOGL2.testJogl2ExtensionCheck(testJOGL2.java:29)
        at testJOGL2.main(testJOGL2.java:24)
main - NativeWindowFactory.initSingleton(false)
Info: XInitThreads() called for concurrent Thread support
NativeWindowFactory.registerFactory() interface javax.media.nativewindow.NativeWindow -> jogamp.nativewindow.NativeWindowFactoryImpl@1e859c0
NativeWindowFactory firstUIActionOnProcess false
NativeWindowFactory isAWTAvailable false, defaultFactory jogamp.nativewindow.NativeWindowFactoryImpl@1e859c0
X11Util.isFirstX11ActionOnProcess: false
GraphicsConfigurationFactory.registerFactory() class javax.media.nativewindow.x11.X11GraphicsDevice -> jogamp.nativewindow.x11.X11GraphicsConfigurationFactory@1415de6
GraphicsConfigurationFactory.registerFactory() interface javax.media.nativewindow.AbstractGraphicsDevice -> jogamp.nativewindow.DefaultGraphicsConfigurationFactoryImpl@121cc40
GraphicsConfigurationFactory.registerFactory() class javax.media.nativewindow.x11.X11GraphicsDevice -> jogamp.opengl.x11.glx.X11GLXGraphicsConfigurationFactory@1386000
X11 Display(NULL) <:0.0>
GraphicsConfigurationFactory.registerFactory() class javax.media.nativewindow.egl.EGLGraphicsDevice -> jogamp.opengl.egl.EGLGraphicsConfigurationFactory@c5c3ac
java.lang.Exception: X11Util.Display: Created new NamedX11Display[:0.0, 0x918ead8, refCount 1, unCloseable false]. Thread main-SharedResourceRunner
        at jogamp.nativewindow.x11.X11Util.createDisplay(X11Util.java:317)
        at jogamp.opengl.x11.glx.X11GLXDrawableFactory$SharedResourceImplementation.createSharedResource(X11GLXDrawableFactory.java:174)
        at jogamp.opengl.SharedResourceRunner.run(SharedResourceRunner.java:206)
        at java.lang.Thread.run(Thread.java:619)
main-SharedResourceRunner - X11GraphicsDevice.setCloseDisplay(true): X11GraphicsDevice[type X11, connection :0.0, unitID 0, handle 0x918ead8]
chooseCapabilities: Using recommendedIndex: idx 0
Exception in thread "main" java.lang.NullPointerException
        at javax.media.opengl.awt.GLCanvas.toString(GLCanvas.java:748)
        at java.lang.String.valueOf(String.java:2826)
        at java.lang.StringBuilder.append(StringBuilder.java:115)
        at javax.media.opengl.awt.GLCanvas.getChosenGLCapabilities(GLCanvas.java:705)
        at testJOGL2.testJogl2ExtensionCheck(testJOGL2.java:34)
        at testJOGL2.main(testJOGL2.java:24)
main-SharedResourceRunner - X11GraphicsDevice.close(): X11GraphicsDevice[type X11, connection :0.0, unitID 0, handle 0x918ead8]
java.lang.Exception: X11Util.Display: Closing new NamedX11Display[:0.0, 0x918ead8, refCount 1, unCloseable false]. Thread main-SharedResourceRunner
        at jogamp.nativewindow.x11.X11Util.closeDisplay(X11Util.java:342)
        at javax.media.nativewindow.x11.X11GraphicsDevice.close(X11GraphicsDevice.java:96)
        at jogamp.opengl.x11.glx.X11GLXDrawableFactory$SharedResourceImplementation.releaseSharedResource(X11GLXDrawableFactory.java:246)
        at jogamp.opengl.SharedResourceRunner.releaseSharedResources(SharedResourceRunner.java:245)
        at jogamp.opengl.SharedResourceRunner.run(SharedResourceRunner.java:229)
        at java.lang.Thread.run(Thread.java:619)
java.lang.Exception: X11Util.Display: Shutdown (close open / pending Displays: false, open (no close attempt): 0/0, open (no close attempt and uncloseable): 0)
        at jogamp.nativewindow.x11.X11Util.shutdown(X11Util.java:198)
        at jogamp.opengl.x11.glx.X11GLXDrawableFactory.shutdownInstance(X11GLXDrawableFactory.java:320)
        at javax.media.opengl.GLDrawableFactory.shutdownImpl(GLDrawableFactory.java:201)
        at javax.media.opengl.GLDrawableFactory.access$100(GLDrawableFactory.java:91)
        at javax.media.opengl.GLDrawableFactory$2.run(GLDrawableFactory.java:172)
        at java.lang.Thread.run(Thread.java:619)

*********************