我有一个简单的使用JOGL的java应用程序。当我从eclipse运行它,然后关闭应用程序窗口时,javaw.exe仍然在运行。下面是相关代码:JOGL javaw.exe在应用程序关闭后仍然运行
public class App {
private Display mDisplay;
private Shell mShell;
private GL4 mGl;
private int mProgramId;
private int mVsId;
private int mFsId;
// ...
public void start() {
if (!initialize()) {
return;
}
while (!mShell.isDisposed()) {
if (!mDisplay.readAndDispatch()) {
mDisplay.sleep();
}
}
destroy();
}
private void initialize() {
mDisplay = new Display();
mShell = new Shell(mDisplay);
// some SWT and opengl initialization code, which is irrelevant for this issue
// (at least I think so)
// getting GLProfile, GLContext, GL4 etc.
final String vsText = ResourceManager.getShaderText(vsPath);
final String fsText = ResourceManager.getShaderText(fsPath);
mVsId = mGl.glCreateShader(GL4.GL_VERTEX_SHADER);
mFsId = mGl.glCreateShader(GL4.GL_FRAGMENT_SHADER);
mGl.glShaderSource(mVsId, 1, new String[] { vsText }, null, 0);
mGl.glCompileShader(mVsId);
mGl.glShaderSource(mFsId, 1, new String[] { fsText }, null, 0);
mGl.glCompileShader(mFsId);
mProgramId = mGl.glCreateProgram();
mGl.glAttachShader(mProgramId, mFsId);
mGl.glAttachShader(mProgramId, mVsId);
// bind a constant attribute location for positions of vertices
mGl.glBindAttribLocation(mProgramId, 0, "in_Position");
// bind another constant attribute location, this time for color
mGl.glBindAttribLocation(mProgramId, 1, "in_Color");
mGl.glLinkProgram(mProgramId);
// here error code is 0x0 (no error)
int error = mGl.glGetError();
mShell.open();
return true;
}
private void destroy() {
// here error code is 0x502 (GL_INVALID_OPERATION)
int error = mGl.glGetError();
mGl.glDetachShader(mProgramId, mFsId);
mGl.glDetachShader(mProgramId, mVsId);
mGl.glDeleteShader(mFsId);
mGl.glDeleteShader(mVsId);
mGl.glDeleteProgram(mProgramId);
mDisplay.dispose();
}
}
我注释掉了所有的绘制代码和其他大多数的OpenGL/JOGL相关的调用(除了越来越GLProfile,GLContext,GL4这个样本中列出的所有内容)和问题仍然存在。
一般来说,应用程序工作正常,着色器编译和链接没有问题(我使用验证,我没有在此示例中显示),它显示它需要什么。唯一的问题是,在关闭应用程序窗口后(通过按下窗口一角的x),javaw.exe仍然在运行。
仅当我注释掉mGl.glCompileShader(mVsId);
和后续行时,才会删除此问题。如果我离开这一行,javaw.exe将继续运行,所以我猜这个问题与着色器初始化/销毁代码有关。另外,glGetError()在destroy()初始的initialize()和0x502(GL_INVALID_OPERATION)结尾处返回0(无错误)。我知道只有主循环之间没有opengl调用,因为为了测试,我将所有渲染代码注释掉了。
任何想法?
编辑2012年10月3日:
我仍然不知道是什么问题,但因为我更新了显卡驱动程序,“javaw.exe的”终止,因为它应该关闭应用程序后。我有AMD Radeon HD 6870.我目前的驱动版本是2012年7月27日起的8.982版本,我不记得最新版本是什么,但我相信它是从2011年1月左右开始的。
但是,glGetError()在销毁开始时仍然返回0x502,所以我猜还是有问题。
嗨,看看这个[示例](https://jogamp.org/wiki/index.php/Jogl_Tutorial#Hello_Triangle) – elect