LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: oXineteX on November 02, 2005, 10:44:28

Title: glGenLists bug?
Post by: oXineteX on November 02, 2005, 10:44:28
Hello,
i think there is a "little bug". I create a function which generate at runtime new Displaylists. Normal i want to call the function with a button. The Result is this:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
   at org.lwjgl.opengl.GL11.glGenLists(GL11.java:1177)

When i call without GenLists creation all goes fine. When i call the function without an AWT Element (i say: call the function at Frame 200) all goes fine.

Only when i call this function over an AWT/Swing Element.

Any Idea why???


Thanks!


P.S.: Sry my English is not so good, as it should.
Title: glGenLists bug?
Post by: Matzon on November 02, 2005, 10:47:18
OpenGL is not threadsafe. You need to make sure that the thread interacting with OpenGL is the same at all times.
Else you get into some messy context management.
Title: glGenLists bug?
Post by: oXineteX on November 03, 2005, 12:17:59
okai, i understand.

First there is my Main OPENGL thread, which works and call all the functions. Actually my "Mainloop" And than there is a other Thread the "AWT".

So will it work when i only set a flag with the button and the Mainloop call the function, because the flag is set?

oXineteX
Title: glGenLists bug?
Post by: oXineteX on November 03, 2005, 12:35:10
ahm i give me the answer self ;) Yes it works, but is there no other way?
Title: hmmmmm...
Post by: Fool Running on November 03, 2005, 14:39:22
Quote... is there no other way?
Sorry, but no.  Thats what you have to do with OpenGL. :)
Title: glGenLists bug?
Post by: Orangy Tang on November 03, 2005, 18:54:39
If you're doing lots of interaction with the AWT event thread, the flag approach can get messy quickly. A simple solution is to just put all the events into a queue and flush that queue every frame in your main loop.
Title: glGenLists bug?
Post by: Whackjack on November 04, 2005, 18:30:00
Why not just synchronize on the block of code you are executing?
Title: hmmmmm...
Post by: Fool Running on November 04, 2005, 20:57:12
The way I understand it, the native OpenGL contexts aren't able to run in multiple threads, so a synchronize wouldn't work either.
Someone can correct me on this :roll: