Search code examples
javawindowsopengllwjglframebuffer

EXCEPTION_ACCESS_VIOLATION crash in ig9icd64.dll when blitting to the window


When I render to an FBO and blit this FBO to the window and the window is minimized Java throws an EXCEPTION_ACCESS_VIOLATION exception.

This is my code for blitting to the screen and to my understanding, what it does.

//Bind the draw framebuffer to the default (0) 
GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, 0); 
//Bind the read framebuffer to the fbo id
GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, frameBufferID); 
//Setting the draw buffer to the screen
GL11.glDrawBuffer(GL11.GL_BACK); 
//Settiing the read buffer to the color attachment of the fbo
GL11.glReadBuffer(GL30.GL_COLOR_ATTACHMENT0);
if(GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) == GL30.GL_FRAMEBUFFER_COMPLETE) //Checking if the framebuffer is complete
{ 
  //Blitting the frambuffer to the screen
  GL30.glBlitFramebuffer(0, 0, fboWidth, fboHeight, 0, 0, windowWidth, windowHeight, GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST); 
}
//Unbinding the framebuffer
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); 

To prevent the crash I added a check to check if the window is minimized

if(isWindowIconified) return;
//Bind the draw framebuffer to the default (0) 
GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, 0); 
//Bind the read framebuffer to the fbo
GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, frameBufferID); 
//Setting the draw buffer to the screen
GL11.glDrawBuffer(GL11.GL_BACK);
//Settiing the read buffer to the color attachment of the fbo
GL11.glReadBuffer(GL30.GL_COLOR_ATTACHMENT0); 
if(GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) == GL30.GL_FRAMEBUFFER_COMPLETE)
{ 
  //Blitting the frambuffer to the screen
  GL30.glBlitFramebuffer(0, 0, fboWidth, fboHeight, 0, 0, windowWidth, windowHeight, GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST); 
}
//Unbinding the framebuffer
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);

I also added this bit of code when initializing the window

//Setting the window minimisazion callback
glfwSetWindowIconifyCallback(window, new GLFWWindowIconifyCallbackI() { 
  @Override
  public void invoke(long window, boolean iconified) {
    isWindowIconified = iconified;
  }
});

Now the program doesn't crash when I minimize it, but when I press Windows+D to get to the desktop the program still crashes.

Now to my questions: What is the best way to prevent the crash? Why does this happen?

Crash Report

System Information:

OS: Windows 10 Home, Version 10.0.15063

GPU: Intel HD Graphics 520

Driver Version: 20.19.15.4642

OpenGL Version: 4.4


Solution

  • If Java throws an EXCEPTION_ACCESS_VIOLATION exception and it happend in ig9icd64.dll it's probably because you use old Intel GPU drivers. I this case it seems to be the problem because it doesn't happen when I launch the program with my NVIDIA GPU and it didn't crash after I updated my Intel GPU driver.

    If you are not sure where the error happened look for "Native frames:" and "Java frames:" in the crash report. The topmost line shows where the error happend.