【发布时间】:2017-10-28 19:26:09
【问题描述】:
当我渲染到一个 FBO 并将这个 FBO blit 到窗口并且窗口被最小化时,Java 会抛出一个 EXCEPTION_ACCESS_VIOLATION 异常。
这是我在屏幕上进行 blitting 的代码,据我所知,它的作用。
//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);
为了防止崩溃,我添加了一个检查窗口是否最小化
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);
我在初始化窗口的时候也加了这段代码
//Setting the window minimisazion callback
glfwSetWindowIconifyCallback(window, new GLFWWindowIconifyCallbackI() {
@Override
public void invoke(long window, boolean iconified) {
isWindowIconified = iconified;
}
});
现在,当我最小化它时程序不会崩溃,但是当我按 Windows+D 进入桌面时,程序仍然崩溃。
现在回答我的问题: 防止崩溃的最佳方法是什么? 为什么会这样?
系统信息:
操作系统:Windows 10 家庭版,版本 10.0.15063
GPU:英特尔核芯显卡 520
驱动版本:20.19.15.4642
OpenGL 版本:4.4
【问题讨论】:
标签: java windows opengl lwjgl framebuffer