StandardGame and ContextCapabilities

I'm having a problem with some code I'm trying to move from the BaseSimpleGame framework to the StandardGame framework.  The problem appears to be something missing from the setup of the DisplaySystem or its Renderer, but I can't quite figure out what it is.  In the StandardGame version, GLContext.getCapabilities() is returning null, which causes null pointer exceptions in a few functions like the following:


Exception in thread "main" java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glMatrixMode(GL11.java:1960)
at com.jme.scene.state.lwjgl.records.RendererRecord.switchMode(RendererRecord.java:25)
at com.jme.renderer.lwjgl.LWJGLCamera.doFrustumChange(LWJGLCamera.java:172)
at com.jme.renderer.lwjgl.LWJGLCamera.apply(LWJGLCamera.java:134)
at com.jme.renderer.lwjgl.LWJGLCamera.<init>(LWJGLCamera.java:75)
at com.jme.renderer.lwjgl.LWJGLRenderer.createCamera(LWJGLRenderer.java:239)

or:

Exception in thread "main" java.lang.NullPointerException
com.jme.scene.state.lwjgl.LWJGLShaderObjectsState.isSupported(LWJGLShaderObjectsState.java:122)
at com.jme.scene.state.lwjgl.LWJGLShaderObjectsState.<init>(LWJGLShaderObjectsState.java:88)
at com.jme.renderer.lwjgl.LWJGLRenderer.createGLSLShaderObjectsState(LWJGLRenderer.java:380)


Does anyone have any idea what's missing that would be causing these errors?  Both of these functions work just fine when called in a subclass of BaseSimpleGame.

Looks like an OpenGL thread issue… iow, the code is not being called in the opengl thread.

renanse said:

Looks like an OpenGL thread issue... iow, the code is not being called in the opengl thread.


I'm pretty sure the code is in fact being called, but whatever code was supposed to set up the GLContext beforehand is missing.

For the first exception, the code being called is as follows (from LWJGL's GL11.java), with the line throwing the exception in bold:
public static void glMatrixMode(int mode) {
ContextCapabilities caps = GLContext.getCapabilities();
long function_pointer = caps.GL11_glMatrixMode_pointer;
BufferChecks.checkFunctionAddress(function_pointer);
nglMatrixMode(mode, function_pointer);
}


For the second, the exception is being thrown by LWJGLShaderObjectsState.java:
    public boolean isSupported() {
        return GLContext.getCapabilities().GL_ARB_shader_objects &&
                GLContext.getCapabilities().GL_ARB_fragment_shader &&
                GLContext.getCapabilities().GL_ARB_vertex_shader &&
                GLContext.getCapabilities().GL_ARB_shading_language_100;

    }


This implies that the value returned by GLContext.getCapabilities() is null.

Update:  It appears that the problem is not that something is missing from StandardGame, but that it's doing something which causes these functions to break.

Certain methods who access the GL Context need to be called from inside the openGL Thread.

Use the GameTaskQueueManager to call the methods who throw NPE's.



Search the wiki for StandardGame or GameTaskQueue Manager, there are a few good articles describing  the problem.

Core-Dump said:

Certain methods who access the GL Context need to be called from inside the openGL Thread.
Use the GameTaskQueueManager to call the methods who throw NPE's.

Search the wiki for StandardGame or GameTaskQueue Manager, there are a few good articles describing  the problem.


Thanks, Core-Dump.  That helped a lot; it's working now that I moved the functions into the right thread.