GLContext.useContext() NPE

Started by rgrzywinski, July 22, 2004, 03:40:27

Previous topic - Next topic

rgrzywinski

Test:

public static void main(final String[] args)
{
   GLContext.useContext(new Object());
}

This worked in 0.9 but does not in CVS.  An NPE is thrown in GLContext.getExtensionClassesAndNames() because GL11.glGetString(GL11.GL_VERSION) is returning null.  I don't see why since GL11.initNativeStubs() is called.....

Thoughts?

elias

Sort of. I forgot to re-throw an exception in useContext(), so an exception could go unnoticed. It's fixed in CVS now.

- elias

rgrzywinski

"Now" now, or soon now?  And which file?  (Man do I hate CVS!  Where's the changelists?   :) )

Matzon

anonymous cvs can take up to 24 hour to sync...

QuoteUpdate of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/opengl
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6271/src/java/org/lwjgl/opengl

Modified Files:
   GLContext.java
Log Message:
Rethrow exception in GLContext.useContext()

Index: GLContext.java
===================================================================
RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/opengl/GLContext.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- GLContext.java   6 Jul 2004 17:55:13 -0000   1.19
+++ GLContext.java   22 Jul 2004 13:04:34 -0000   1.20
@@ -254,6 +254,7 @@
      } catch (LWJGLException e) {
         if (did_auto_load)
            unloadOpenGLLibrary();
+         throw e;
      }
   }

You might want to subscribe to the cvs mailing list (http://sourceforge.net/mail/?group_id=58488) or join our IRC channel (irc://irc.freenode.net/lwjgl) for reports from the CVS bot

rgrzywinski

Ppfth!  Thanks for the diff.  That will get me movin'!

Just curious:  what's with the delay?  Those 1000 monkeys at the 1000 typewriters got a union now?   :D

rgrzywinski

Perhaps I'm confused.  As far as I can tell (since CVS has been updates) the only change was to rethrow an exception that I wasn't getting ....  Here's my stack trace:

java.lang.NullPointerException
   at org.lwjgl.opengl.GLContext.getExtensionClassesAndNames(GLContext.java:263)
   at org.lwjgl.opengl.GLContext.loadStubs(GLContext.java:343)
   at org.lwjgl.opengl.GLContext.useContext(GLContext.java:251)

For the rethrow that you added to be relevant in this case GL11.initNativeStubs() would had to throw but it can't since I'm getting to loadStubs().

At the end of the day, glGetString() just isn't being bound for some reason.  To be 100% clear, my test code is:


public static void main(final String[] args) 
{ 
    try
    {
        GLContext.useContext(new Object()); 
    } catch(final LWJGLException e)
    {
        e.printStackTrace();
    }
}

rgrzywinski

Perhaps I'm confused.  As far as I can tell (since CVS has been updated) the only change was to rethrow an exception that I wasn't getting ....  Here's my stack trace:

java.lang.NullPointerException
    at org.lwjgl.opengl.GLContext.getExtensionClassesAndNames(GLContext.java:263)
    at org.lwjgl.opengl.GLContext.loadStubs(GLContext.java:343)
    at org.lwjgl.opengl.GLContext.useContext(GLContext.java:251)
    ...


For the rethrow that you added to be relevant in this case GL11.initNativeStubs() would had to throw but it can't since I'm getting to loadStubs().

At the end of the day, glGetString() just isn't being bound for some reason.  To be 100% clear, my test code is:


public static void main(final String[] args) 
{ 
    try
    {
        GLContext.useContext(new Object()); 
    } catch(final LWJGLException e)
    {
        e.printStackTrace();
    }
}

elias

I'll take a look tomorrow.

- elias

elias

I know: You have to have a context current before you call GLContext.useContext().  I've added a comment about it in GLContext.java.

- elias

rgrzywinski

Well I'll be a monkey's uncle (not one of those unionized monkeys though!).

I can even get it to work with my crazy crazy crazy code.  And, when all's said and done, the code is more "sane" now.

Thanks for the head's up.

princec

LWJGL works with *everything* :) Something the JOGL lot haven't gotten their heads round.

Cas :)

rgrzywinski

Going back to this "bug", I don't suppose that you could add some sanity checking to getExtensionClassesAndNames() so that when I'm dickering around with other bindings to LWJGL that I get a useful error message?

If the Gl context passed to org.lwjgl.opengl.GLContext.useContext(glContext) is not current, then getExtensionClassesAndNames()'s:

String version = GL11.glGetString(GL11.GL_VERSION);


returns null.  Perhaps adding:

final String version = GL11.glGetString(GL11.GL_VERSION);
if(version == null)
    throw new WhateverTheHeckRuntimeException("No GL version was available.  Is the GL context current?");
/* else -- a version was available */


Thanks!

elias

Sounds fair enough. It's comitted to CVS.

- elias

rgrzywinski

Thank you very much.

Nice going on the Mac port by the way!  Now I just need to buy a mac to port my bindings to it.   :shock:

princec

You'll be wanting a new Mac Mini then. Like everyone else.

Cas :)