[Bug] gl.glGenFramebuffersEXT Causes JVM Crash

I am writing a small game in java and started coded a FBO class. When I tested it the following appeared in my console

[quote]#

An unexpected error has been detected by Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6959e29b, pid=1872, tid=3616

Java VM: Java HotSpot™ Client VM (10.0-b22 mixed mode, sharing windows-x86)

Problematic frame:

C [nvoglv32.dll+0x9e29b]

An error report file with more information is saved as:

J:\Programming\Java\Game Workspace\Game\hs_err_pid1872.log

If you would like to submit a bug report, please visit:

http://java.sun.com/webapps/bugreport/crash.jsp

The crash happened outside the Java Virtual Machine in native code.

See problematic frame for where to report the bug.

[/quote]
Using the following code (The code is called from the display method of my Canvas - so the thread has got context):


		//Get the openGL object (with context!)
		GL gl = GraphicsManager.getGL();
		
		//Create a valid handle to manage the frame buffer
		//this.intBuffer = IntBuffer.allocate(1);
		//gl.glGenFramebuffersEXT(1, this.intBuffer);
		gl.glGenFramebuffersEXT(1, ints, 0);
		this.fbo = ints[0]; 
		//this.fbo = this.intBuffer.get(0);
		
		//Bind the FBO
		gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, this.fbo);
		
		//Create a depth buffer
		//this.intBuffer = IntBuffer.allocate(1);
		gl.glGenRenderbuffersEXT(1, ints, 1); //this.intBuffer);
		this.depthBuffer = ints[1];
		//this.depthBuffer = this.intBuffer.get(0);
		
		//Bind the render buffer
		gl.glBindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, this.depthBuffer);
		
		//Tell openGL how much storeage space we want for the render buffer
		gl.glRenderbufferStorageEXT(GL.GL_RENDERBUFFER_EXT, GL.GL_DEPTH_COMPONENT, width, height);
		
		//Now attach the render buffer to the FBO we created
		gl.glFramebufferRenderbufferEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_RENDERBUFFER_EXT, this.depthBuffer);
		
		//Create a texture handle
		//this.intBuffer = IntBuffer.allocate(1);
		gl.glGenTextures(1, ints, 2); //this.intBuffer);
		this.color_texture = ints[2];
		//this.color_texture = this.intBuffer.get(0);
		
		//Bind the handle as a 2D texture
		gl.glBindTexture(GL.GL_TEXTURE_2D, this.color_texture);
		
		//Set texture parameters
		gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
		gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
		gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
		gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);

		//Create a image of the same width and height as the render buffer
		gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA8, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, null);
		
		//Attach the colour texture to the FBO
		gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT, GL.GL_TEXTURE_2D, this.color_texture, 0);
		
		
		int status = gl.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_EXT);
		
		this.active = true;
		
		if (status != GL.GL_FRAMEBUFFER_COMPLETE_EXT)
			throw new Exception("FBO Creation Error");
		//Get the openGL object (with context!)
		GL gl = GraphicsManager.getGL();
		
		//Create a valid handle to manage the frame buffer
		//this.intBuffer = IntBuffer.allocate(1);
		//gl.glGenFramebuffersEXT(1, this.intBuffer);
		gl.glGenFramebuffersEXT(1, ints, 0);
		this.fbo = ints[0]; 
		//this.fbo = this.intBuffer.get(0);
		
		//Bind the FBO
		gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, this.fbo);
		
		//Create a depth buffer
		//this.intBuffer = IntBuffer.allocate(1);
		gl.glGenRenderbuffersEXT(1, ints, 1); //this.intBuffer);
		this.depthBuffer = ints[1];
		//this.depthBuffer = this.intBuffer.get(0);
		
		//Bind the render buffer
		gl.glBindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, this.depthBuffer);
		
		//Tell openGL how much storeage space we want for the render buffer
		gl.glRenderbufferStorageEXT(GL.GL_RENDERBUFFER_EXT, GL.GL_DEPTH_COMPONENT, width, height);
		
		//Now attach the render buffer to the FBO we created
		gl.glFramebufferRenderbufferEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_RENDERBUFFER_EXT, this.depthBuffer);
		
		//Create a texture handle
		//this.intBuffer = IntBuffer.allocate(1);
		gl.glGenTextures(1, ints, 2); //this.intBuffer);
		this.color_texture = ints[2];
		//this.color_texture = this.intBuffer.get(0);
		
		//Bind the handle as a 2D texture
		gl.glBindTexture(GL.GL_TEXTURE_2D, this.color_texture);
		
		//Set texture parameters
		gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
		gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
		gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
		gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);

		//Create a image of the same width and height as the render buffer
		gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA8, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, null);
		
		//Attach the colour texture to the FBO
		gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT, GL.GL_TEXTURE_2D, this.color_texture, 0);
		
		
		int status = gl.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_EXT);
		
		this.active = true;
		
		if (status != GL.GL_FRAMEBUFFER_COMPLETE_EXT)
			throw new Exception("FBO Creation Error");


I have narrowed the line of code which caused the error to the third line; gl.glGenFramebuffersEXT(1, ints, 0);

I have a game logic thread running as well as a render thread. When I do not run the game logic thread the FBO is created without an issue. However stopping my logic thread to create FBO’s when I need them doesnt really lend itself to good game play.

The logic thread does no interact with the FBO class in any way so I am at a lost of why it is happening. Does anybody have a solution with does not involve either pausing my logic thread or creating all fbo’s at engine startup?

Does your logic thread access the “ints” variable? Possibly the logic thread is uninitializing that variable? There’s not much that can go wrong with that method.

No, at no point does the logic thread even access the FBO class

So you are sure that the “ints” variable is created, initialized and is never modified by the logic thread? Does the logic thread make any GL calls at all? That’s just a little odd that the code works when the logic thread is paused but doesn’t work when it’s running, assuming that it doesn’t alter the “ints” variable in anyway.

I’m pretty sure you can keep fbo’s around for a while instead of creating a new one whenever you need it. Perhaps it’s better to initialize them once in the beginning – where you can stop the logic thread – and reuse any fbo id’s later on for effects.