LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: rgrzywinski on July 22, 2004, 03:40:27

Title: GLContext.useContext() NPE
Post by: rgrzywinski on July 22, 2004, 03:40:27
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?
Title: GLContext.useContext() NPE
Post by: elias on July 22, 2004, 12:50:53
Sort of. I forgot to re-throw an exception in useContext(), so an exception could go unnoticed. It's fixed in CVS now.

- elias
Title: GLContext.useContext() NPE
Post by: rgrzywinski on July 22, 2004, 13:02:33
"Now" now, or soon now?  And which file?  (Man do I hate CVS!  Where's the changelists?   :) )
Title: GLContext.useContext() NPE
Post by: Matzon on July 22, 2004, 13:28:31
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
Title: GLContext.useContext() NPE
Post by: rgrzywinski on July 22, 2004, 13:34:30
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
Title: GLContext.useContext() NPE
Post by: rgrzywinski on July 22, 2004, 14:45:46
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();
   }
}
Title: GLContext.useContext() NPE
Post by: rgrzywinski on July 22, 2004, 14:45:46
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();
   }
}
Title: GLContext.useContext() NPE
Post by: elias on July 22, 2004, 14:58:25
I'll take a look tomorrow.

- elias
Title: GLContext.useContext() NPE
Post by: elias on July 22, 2004, 15:45:39
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
Title: GLContext.useContext() NPE
Post by: rgrzywinski on July 22, 2004, 16:27:15
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.
Title: GLContext.useContext() NPE
Post by: princec on July 23, 2004, 09:21:53
LWJGL works with *everything* :) Something the JOGL lot haven't gotten their heads round.

Cas :)
Title: GLContext.useContext() NPE
Post by: rgrzywinski on January 12, 2005, 02:37:16
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!
Title: GLContext.useContext() NPE
Post by: elias on January 12, 2005, 08:56:30
Sounds fair enough. It's comitted to CVS.

- elias
Title: GLContext.useContext() NPE
Post by: rgrzywinski on January 12, 2005, 12:37:29
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:
Title: GLContext.useContext() NPE
Post by: princec on January 12, 2005, 13:02:09
You'll be wanting a new Mac Mini then. Like everyone else.

Cas :)