Teture null pointer error in OS X Tiger

Started by mark, February 23, 2006, 11:47:38

Previous topic - Next topic

mark

I'm using Eclipse and SWT to create an OpenGL program. It is based on the Eclipse Foundation's snippet 195 found at:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet195.java?rev=HEAD&content-type=text/vnd.viewcvs-markup

I've replaced the torus with a simple gluSphere (this works fine). I'm now trying to put a texture map onto the GLUsphere, but I'm getting a runtime error with glGenTextures(). In particular the following seems to cause problems despite compiling fine:

  IntBuffer textureID = BufferUtils.createIntBuffer(1);
  GL11.glGenTextures(textureID);

The following runtime error occurs:

Exception in thread "main" java.lang.NullPointerException
   at org.lwjgl.opengl.GL11.glGenTextures(GL11.java:1206)
   at Schumann_LWJGL.main(Schumann_LWJGL.java:69)

I have tried alternatives, including .allocateDirect (which only seems to be possible with a ByteBuffer).

I'm at a loss, and don't have time to look into the lwjgl source so any feedback would be appreciated. Let me know if I should post the whole source or any other information.

Matzon

you need to make sure a context is valid, and current for the thread

mark

Thanks for the feedback. I've been preparing the texture in the main thread so I doubt that is causing the issue. I do the rendering in a separate thread so I could pershaps understand it coming up as a problem later, but I haven't got that far yet. How do I make sure the context is valid? Any chance you could be a little more specific/ provide some code suggestions? Thanks again.

Matzon

canvas.setCurrent();
GLContext.useContext(canvas);

are the two methods that you must call - generally you should try to do all of the work on 1 thread because opengl isn't really thread safe

mark

Okay, that's sorted it out. I had already done that in an init function, but I put the texture map code before calling init. Seems really obvious now, but I spent a whole day trying to work it out. Thanks for the help.