Trouble with GLContext

Started by sthorsen, November 15, 2005, 13:41:20

Previous topic - Next topic

sthorsen

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)

CaseyB

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?

sthorsen

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

CaseyB

Oooh, sorry, I can't help you there.  I know nothing about picking, but hopefully someone can help you! Sorry!

Fool Running

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).
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

sthorsen

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.

Fool Running

Quote
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)
Unless I'm missing something (Which is highly likely  :lol: ), that looks like a stack for the main thread.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

sthorsen

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

sthorsen

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!