husker-dev / openglfx

OpenGL implementation for JavaFX
Apache License 2.0
80 stars 10 forks source link

AsyncBlitCanvasImpl can't be re-created once a previous instance was disposed #57

Closed streamingdv closed 7 months ago

streamingdv commented 7 months ago

Encountered during my memory leak investigation with sw pipeline enabled, a second call to

GLCanvas.create(LWJGLExecutor.LWJGL_MODULE, GLProfile.Core, false, 0, true)

will fail with

Exception in thread "Thread-5" java.lang.IllegalStateException: There is no OpenGL context current in the current thread.
    at org.lwjgl.opengl.GL.createCapabilities(GL.java:382)
    at org.lwjgl.opengl.GL.createCapabilities(GL.java:311)
    at org.lwjgl.opengl.GL.createCapabilities(GL.java:295)
    at com.huskerdev.openglfx.lwjgl.LWJGLExecutor.initGLFunctions(LWJGLExecutor.kt:15)
    at com.huskerdev.openglfx.canvas.implementations.async.AsyncBlitCanvasImpl$initializeThread$1.invoke(AsyncBlitCanvasImpl.kt:60)
    at com.huskerdev.openglfx.canvas.implementations.async.AsyncBlitCanvasImpl$initializeThread$1.invoke(AsyncBlitCanvasImpl.kt:57)
    at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)

once you have already disposed an AsyncBlitCanvasImpl. Only AsyncBlitCanvasImpl is affected.

husker-dev commented 7 months ago

Is it Windows platform?

streamingdv commented 7 months ago

Yes it's happening on Windows, did not yet tried it on Linux.

husker-dev commented 7 months ago

The error occurred because the GLContext was created in a new thread, and JavaFX sometimes managed to run this thread again, because I didn't see the new GLContext. Fixed.