LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: sthorsen on November 15, 2005, 13:41:20

Title: Trouble with GLContext
Post by: sthorsen on November 15, 2005, 13:41:20
Hi!

I'm trying to get the following code to run. I haven't created a Display since the rendering is done to an AWTGLCanvas. The graphical rendering works fine but when I try to do a rendering pass in GL_SELECTION I get a NullPointerException. I assume that I have some GLContext troube. Well here is the code and the exception:


...
int buffer[] = new int[512];
int viewport[] = new int[16];
IntBuffer temp = BufferUtils.createIntBuffer(16);
GL11.glGetInteger(GL11.GL_VIEWPORT, temp);
...



Exception in thread "main" java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glGetInteger(GL11.java:1161)
at org.flagfootball.graphics.scenegraph.GLPickNode.pick(GLPickNode.java:35)
at org.flagfootball.graphics.FlagRenderer.pick(FlagRenderer.java:60)
at org.flagfootball.graphics.gui.FlagFootballGUI.update(FlagFootballGUI.java:84)
at org.flagfootball.ASCIISimulator.play(ASCIISimulator.java:117)
at org.flagfootball.ASCIISimulator.main(ASCIISimulator.java:45)
Title: Trouble with GLContext
Post by: CaseyB on November 15, 2005, 14:13:23
I have had a lot of trouble with that kind of thing and AWTGLCanvases.  Mostly the trouble that I run into is timing.  If the canvas is not displayable yet then it doesn't have a valid GLContext and that always results in a null pointer for me!  That may or may not be the trouble that you're having, can you give a little more information about the behavior of your app?
Title: Trouble with GLContext
Post by: sthorsen on November 15, 2005, 15:24:58
The canvas is displayable because it is rendered. When i press start game the game works fine unless i have enabled mouse picking. If that is enabled i get a nullpointerexception when pressing start (even in this case there the canvas is still rendered correctly).
Thanks for your time - I hope the problem will be solved  :D
Title: Trouble with GLContext
Post by: CaseyB on November 15, 2005, 15:37:09
Oooh, sorry, I can't help you there.  I know nothing about picking, but hopefully someone can help you! Sorry!
Title: hmmmmmmm....
Post by: Fool Running on November 15, 2005, 17:04:34
It looks like you are trying to run the picking in a separate thread than the AWT event thread (I could be wrong :lol: ).
OpenGL is not thread safe. :cry:  You have to do all of your rendering (including picking) in the same thread (if you have an AWTGLCanvas then they all have to be rendered using the AWT event thread).
Title: Trouble with GLContext
Post by: sthorsen on November 15, 2005, 17:14:40
Thanks for the input! I believe that the picking is run on the same thread as the rendering (which works) but if there is a way to check it I will do that. I will look into it all tomorrow.
Title: hmmmmm...
Post by: Fool Running on November 15, 2005, 18:48:38
QuoteException in thread "main" java.lang.NullPointerException
  at org.lwjgl.opengl.GL11.glGetInteger(GL11.java:1161)
  at org.flagfootball.graphics.scenegraph.GLPickNode.pick(GLPickNode.java:35)
  at org.flagfootball.graphics.FlagRenderer.pick(FlagRenderer.java:60)
  at org.flagfootball.graphics.gui.FlagFootballGUI.update(FlagFootballGUI.java:84)
  at org.flagfootball.ASCIISimulator.play(ASCIISimulator.java:117)
  at org.flagfootball.ASCIISimulator.main(ASCIISimulator.java:45)
Unless I'm missing something (Which is highly likely  :lol: ), that looks like a stack for the main thread.
Title: Trouble with GLContext
Post by: sthorsen on November 15, 2005, 18:53:44
You're right about that. I think I might know why the picking code has ended up being called on the wrong thread. I will return after I have looked at the code tomorrow
Title: Trouble with GLContext
Post by: sthorsen on November 18, 2005, 14:30:09
You were right! I called the picking code from the wrong thread. I moved to call to the picking method to a mouseListener method and now everything works flawlessly. Thank you for your time!