私は現在JavaとLWJGL 3で作業していますが、頂点配列オブジェクト、頂点バッファオブジェクトなどのようなもののためのラッパーを作成しています。 これは良い習慣ですこれらのオブジェクトはプログラムが終了する前に、私はクリーンアップを行うことになっているシャットダウンフックを作成しました。LWJGL - シャットダウンフックでOpenGLコンテキストが失われる
しかし、シャットダウンフック内でOpenGL関数を呼び出すと、OpenGLコンテキストが初期化されていないという不正な状態例外が発生します。
私はこの動作を再現するテストプログラムを書いている:
public static void main(String[] args) {
GLFW.glfwInit();
long window = GLFW.glfwCreateWindow(100, 100, "", 0, 0);
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
GL15.glDeleteBuffers(0);
GLFW.glfwTerminate();
}
});
while (!GLFW.glfwWindowShouldClose(window)) {
GLFW.glfwPollEvents();
}
}
スタックトレース:
Exception in thread "Thread-0" java.lang.IllegalStateException: No GLCapabilities instance set for the current thread. Possible solutions:
a) Call GL.createCapabilities() after making a context current in the current thread.
b) Call GL.setCapabilities() if a GLCapabilities instance already exists for the current context.
at org.lwjgl.opengl.GL.getCapabilities(GL.java:241)
at org.lwjgl.opengl.GL15.nglDeleteBuffers(GL15.java:152)
at org.lwjgl.opengl.GL15.glDeleteBuffers(GL15.java:178)
at core.Main$1.run(Main.java:11)
をコンテキストが自動的に破棄されます、なぜ誰もが知っていますか?
追加情報が必要な場合は、そう言います。
シャットダウンフックの目的は何ですか? 'glfwWindowShouldClose'は十分ではありませんか? –
OpenGLコンテキストは、特定のスレッドにバインドされていることに注意してください。新しいスレッドを作成しているので、使用する前にコンテキストをバインドする必要があります。 – BDL
@NicolBolasいいえ、私はこのインタフェースを他のクラスと切り離したいので、disposeAllメソッドなどを呼びたくはありません。 – RagingRabbit