JDK-8114426 : Prism/ES2: FX application with multiple stages throws GLException on Windows
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: fx2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2011-07-06
  • Updated: 2015-06-16
  • Resolved: 2011-08-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
fx2.0Fixed
Related Reports
Relates :  
Description
To reproduce the issue just run any sample with multiple FX stages (for example, HelloAlert, HelloModality).

The stack trace of the exception:

     [java] com.sun.prism.opengl.GLException: Context not current on current thread
     [java]     at com.sun.prism.opengl.impl.GLContextImpl.release(GLContextImpl.java:190)
     [java]     at com.sun.prism.opengl.impl.windows.wgl.WindowsExternalWGLContext.release(WindowsExternalWGLContext.java:101)
     [java]     at com.sun.prism.es2.ES2Context$State.releaseCurrentContext(ES2Context.java:432)
     [java]     at com.sun.prism.es2.ES2Context.makeCurrentState(ES2Context.java:75)
     [java]     at com.sun.prism.es2.ES2Context.updateRenderTarget(ES2Context.java:136)
     [java]     at com.sun.prism.es2.ES2Context.updateRenderTarget(ES2Context.java:113)
     [java]     at com.sun.prism.es2.ES2Context.updateRenderTarget(ES2Context.java:36)
     [java]     at com.sun.prism.impl.ps.BaseShaderContext.setRenderTarget(BaseShaderContext.java:625)
     [java]     at com.sun.prism.impl.BaseContext.setRenderTarget(BaseContext.java:67)
     [java]     at com.sun.prism.impl.BaseGraphics.<init>(BaseGraphics.java:81)
     [java]     at com.sun.prism.impl.ps.BaseShaderGraphics.<init>(BaseShaderGraphics.java:44)
     [java]     at com.sun.prism.es2.ES2Graphics.<init>(ES2Graphics.java:19)
     [java]     at com.sun.prism.es2.ES2Graphics.create(ES2Graphics.java:33)
     [java]     at com.sun.prism.es2.ES2SwapChain.createGraphics(ES2SwapChain.java:153)
     [java]     at com.sun.prism.es2.ES2SwapChain.createGraphics(ES2SwapChain.java:21)
     [java]     at com.sun.javafx.tk.quantum.PaintRunnable.run(PaintRunnable.java:233)
     [java]     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
     [java]     at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
     [java]     at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
     [java]     at com.sun.prism.render.RenderJob.run(RenderJob.java:29)
     [java]     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
     [java]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
     [java]     at com.sun.javafx.tk.quantum.QuantumRenderer$ObservedRunnable.run(QuantumRenderer.java:70)
     [java]     at java.lang.Thread.run(Thread.java:619)

The root cause of the issue seems to be inconsistency between managing OpenGL rendering contexts on Mac and managing contexts on Windows.

In Prism/ES2 we maintain "external" GLContext instances: external GLContext instance is created for each native OpenGL rendering context and it represents the existing native OpenGL rendering context created.
(here's more info about the external JOGL contexts - runtime\prism-jogl\src\jogl\classes\com\sun\prism\opengl\GLDrawableFactory.java, GLDrawableFactory.createExternalGLContext).

On Mac, Glass provides some API for managing the native OpenGL rendering contexts (and calls to makeCurrent/release on the corresponding external GLContext instances have no effect).

The particular place (where Glass makes the native rendering contexts current or releases the context) is Pen.begin and Pen.end. On Windows, the implementation of the Pen.begin/end methods is no-op and the current native OpenGL rendering context never changes and this implicitly causes the GLException exception to be thrown.

If we want to continue managing OpenGL rendering contexts from Quantum/Glass (like Quantum/Glass already does on Mac), it probably makes sense to implement the following items on Windows (to be consistent with Mac-implementation):

1. move the creation of native OpenGL rendering contexts from Prism/ES2 to Glass

in Prism/ES2 it's currently implemented here - prism-jogl\src\jogl\classes\com\sun\prism\opengl\impl\windows\wgl\WindowsWGLDrawableFactory.java, WindowsWGLDrawableFactory.createNativeGLContext

2. provide implementation of the Pen.begin/end method (make native OpenGL rendering current/restore previous OpenGL native context).
Comments
verified on build 42.
30-08-2011

Here's some notes regarding the final fix: 1. the fix introduces new View parameter in ResourceFactory.createRenderingContext method - if view isn't null, then the method returns a rendering context associated with the specified view, - if view is null, then the method returns an offscreen rendering context 2. rendering contexts are proposed to be created through GLDrawable.createGLDrawable interface so that the contexts aren't external anymore and maintained by JOGL. The goal of the fix is to have consistency with recent "offscreen rendering" changes (RT-13728) and try to keep Glass rendering neutral. The changeset is: Changeset: 25d0ab0f3dc3 Author: dcherepanov Date: Mon Aug 01 18:27:53 2011 +0400 URL: http://jfxsrc.us.oracle.com/javafx/presidio/scrum/graphics/runtime/rev/25d0ab0f3dc3
01-08-2011