glClearBufferfv causes EXCEPTION_ACCESS_VIOLATION

Started by Troncoso, January 01, 2016, 23:10:28

Previous topic - Next topic

Troncoso

I'm trying to clear my window with glClearBufferfv instead of glClear, but it throws an EXCEPTION_ACCESS_VIOLATION. My setup is very simple:

                if (glfwInit() != GLFW_TRUE)
		{
			Log.error("Failed to initialize GLFW");
			return;
		}
		
		glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
		glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
		

		glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
		
		glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
		glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
		glfwWindowHint(GLFW_SAMPLES, 0);
		glfwWindowHint(GLFW_STEREO, GLFW_FALSE);
		
		window = glfwCreateWindow(800, 600, info.title, NULL, NULL);
		
		if (window == NULL)
		{
			Log.error("Failed to open window");
			return;
		}
		
		glfwMakeContextCurrent(window);

                GL.createCapabilities();

                do
		{
			float[] red = {1.0f, 0.0f, 0.0f, 1.0f};
        	        FloatBuffer buffer = FloatBuffer.wrap(red);
        	        GL30.glClearBufferfv(GL11.GL_COLOR, 0, buffer);
			
			glfwSwapBuffers(window);
			glfwPollEvents();
			
			running &= glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_RELEASE;
			running &= glfwWindowShouldClose(window) != GLFW_TRUE;
			
		} while (running);

                glfwDestroyWindow(window);
		glfwTerminate();
               


Using glClearColor and glClear works fine, though. Looking at the hs_err_pid log, I see this:

siginfo: ExceptionCode=0xc0000005, reading address 0x0000000000000000

which I imagine means the code is trying to read from a null pointer. That would make me think it's talking about my FloatBuffer, but it's not null as far as I can tell. I don't know what other information might be useful here, but let me know and I'll post more. Thanks for any help in advance.

Kai

You must use direct Java NIO Buffers with LWJGL, and cannot use a wrapped/non-direct/Java-heap buffer.
(also, your wrapped FloatBuffer would have the wrong endianness this way.)
Thought: Maybe o.l.s.Checks.checkBuffer() should also check whether Buffer.isDirect() is true.

Use this instead:
float[] red = {1.0f, 0.0f, 0.0f, 1.0f};
FloatBuffer buffer = BufferUtils.createFloatBuffer(4);
buffer.put(red).flip();
GL30.glClearBufferfv(GL11.GL_COLOR, 0, buffer);

Troncoso


spasi

Quote from: Kai on January 01, 2016, 23:20:56Thought: Maybe o.l.s.Checks.checkBuffer() should also check whether Buffer.isDirect() is true.

I plan on writing a more complete getting started guide and making sure new users don't start anything without reading it. It will explain fundamentals like direct buffers, .flip()ing, etc. Also how to debug common issues (e.g. using OpenGL debug contexts).