Hello Guest

Why is GL.createCapabilities() giving a nullPointerException?

  • 1 Replies
Specifically the variable 'context' in Context context = CURRENT_CONTEXT.get(); in Class org.lwjglx.debug.opengl.GL on line 38 is null.

My code leading up to it:

Code: [Select]
public static void main(String[] args)
new Game().start();

private synchronized void start()
mainThread = new Thread(this, "main");

public void run()
window = new Window(W, H, title);
               <game loop here>

Code: [Select]
public class Window{

private long window;
        private int width, height;
private String title;
private Input input;

public Window(int width, int height, String title)
this.width = width;
this.height = height;
this.title = title;

public void create()


window = GLFW.glfwCreateWindow(width, height, title, 0, 0);

GLFWVidMode vidMode = GLFW.glfwGetVideoMode( GLFW.glfwGetPrimaryMonitor() );
GLFW.glfwSetWindowPos(window, ( (vidMode.width() - width) / 2 ), ( (vidMode.height() - height) / 2 ) );

GL.createCapabilities();     //<--- HERE

GLFW.glfwSetKeyCallback(window, input.getKeyboardCallback());
GLFW.glfwSetCursorPosCallback(window, input.getMouseMoveCallback());
GLFW.glfwSetMouseButtonCallback(window, input.getMouseButtonsCallback());



Re: Why is GL.createCapabilities() giving a nullPointerException?
« Reply #1 on: March 10, 2020, 04:14:50 »
The first step is to check the return of glGetError() on every step of the way to determine where something may have gone wrong.

Just do something like
int error = glGetError();
after every GL call, and check out the return code (you can find the codes in the same file that contains the definition for the function itself).

This may already be enough to put you on a right track.
If I have something wrong with my rendering, I just check the error after every operation, debug the code and then google the errors I received and what may have casued them. This is usually enough to tell me exactly what is missing.