Why is GL.createCapabilities() giving a nullPointerException?

Started by nullpointer, March 06, 2020, 21:17:36

Previous topic - Next topic

nullpointer

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:

public static void main(String[] args)
	{
		new Game().start();
	}

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

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


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()
	{

		iGLFW.glfwInit()
		
		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 ) );
		GLFW.glfwMakeContextCurrent(window);
		
		GL.createCapabilities();     //<--- HERE
		
		GLFW.glfwSetKeyCallback(window, input.getKeyboardCallback());
		GLFW.glfwSetCursorPosCallback(window, input.getMouseMoveCallback());
		GLFW.glfwSetMouseButtonCallback(window, input.getMouseButtonsCallback());
		
		GLFW.glfwShowWindow(window);
		
		GLFW.glfwSwapInterval(1);		
	}

Aisaaax

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.