diff options
author | Sven Gothel <[email protected]> | 2011-11-28 03:06:13 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-11-28 03:06:13 +0100 |
commit | 97218b88af9113740b3704a3666d7356cdc83cd0 (patch) | |
tree | e43072323a424d745225528b16d2f990c72c3394 /src/jogl/classes/jogamp/opengl/macosx/cgl | |
parent | ebfaa1263a6739b1e9bcdad48c2447c71f94106e (diff) |
Fix Bug 527: Creating a context w/ shared context, while the latter is in use (threading)
Bug 527 describes the situation where wglShareLists() fails (throws exception)
while the shared context is in use by another thread (some Animator).
It was reported by Jerome Jouvie.
The exception happens not everytime, but at least around 20% on manual tests
I have performed on the Windows platform.
The context in question are all JOGL's GL2, which natively where bound to an OpenGL 3.0 profile.
The WGL_ARB_create_context spec says http://www.opengl.org/registry/specs/ARB/wgl_create_context.txt:
+++
Future versions of OpenGL may only support being added to a share
group at context creation time. Specifying such a version of a
context as either the <hglrc1> or <hglrc2> arguments to
wglShareLists will fail. wglShareLists will return FALSE, and
GetLastError will return ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB.
+++
Hence the 1st patch was to remove 'wglShareLists()' usage in case
we use the new WGL_ARB_create_context context creation method.
Even though this is a desired change, and works in general, it didn't fix the issue.
It seems that the shared context, which is passed @ new context creation,
cannot be used while it is in use itself in another thread.
This conclusion leads to the actual fix, ie. locking the shared context
while creating the new context which shares it.
Manual tests using this patch could not reproduce this issue (40 attempts).
Test: TestSharedContextListNEWT2
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/macosx/cgl')
4 files changed, 20 insertions, 17 deletions
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java index d5ce6a196..d063c3a7b 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java @@ -54,7 +54,6 @@ import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; import jogamp.opengl.GLContextImpl; -import jogamp.opengl.GLContextShareSet; import jogamp.opengl.GLDrawableImpl; import jogamp.opengl.GLGraphicsConfigurationUtil; import jogamp.opengl.macosx.cgl.MacOSXCGLDrawable.GLBackendType; @@ -204,35 +203,35 @@ public abstract class MacOSXCGLContext extends GLContextImpl return false; } - protected long createImplPreset() throws GLException { - MacOSXCGLContext other = (MacOSXCGLContext) GLContextShareSet.getShareContext(this); + protected long createImplPreset(GLContextImpl shareWith) throws GLException { long share = 0; - if (other != null) { + if (shareWith != null) { // Change our OpenGL mode to match that of any share context before we create ourselves - setOpenGLMode(other.getOpenGLMode()); - share = other.getHandle(); + setOpenGLMode(((MacOSXCGLContext)shareWith).getOpenGLMode()); + share = shareWith.getHandle(); if (share == 0) { throw new GLException("GLContextShareSet returned a NULL OpenGL context"); } } + MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration(); GLCapabilitiesImmutable capabilitiesChosen = (GLCapabilitiesImmutable) config.getChosenCapabilities(); - if (capabilitiesChosen.getPbufferFloatingPointBuffers() && - !isTigerOrLater) { + if (capabilitiesChosen.getPbufferFloatingPointBuffers() && !isTigerOrLater) { throw new GLException("Floating-point pbuffers supported only on OS X 10.4 or later"); } GLProfile glp = capabilitiesChosen.getGLProfile(); if(glp.isGLES1() || glp.isGLES2() || glp.isGL4() || glp.isGL3() && !isLionOrLater) { throw new GLException("OpenGL profile not supported on MacOSX "+Platform.getOSVersionNumber()+": "+glp); } + if (DEBUG) { System.err.println("!!! Share context is " + toHexString(share) + " for " + this); } - return share; + return share; } - - protected boolean createImpl() throws GLException { - long share = createImplPreset(); + + protected boolean createImpl(GLContextImpl shareWith) throws GLException { + long share = createImplPreset(shareWith); contextHandle = createContextARB(share, true); return 0 != contextHandle; } diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java index ba384fc71..2b24ed378 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java @@ -50,6 +50,7 @@ import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLException; import jogamp.nativewindow.WrappedSurface; +import jogamp.opengl.GLContextImpl; import jogamp.opengl.GLContextShareSet; import jogamp.opengl.macosx.cgl.MacOSXCGLDrawable.GLBackendType; @@ -117,7 +118,7 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext { return new MacOSXExternalCGLContext(new Drawable(factory, ns), isNSContext, contextHandle); } - protected boolean createImpl() throws GLException { + protected boolean createImpl(GLContextImpl shareWith) throws GLException { return true; } diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLContext.java index 4fe6fa484..6de94085f 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLContext.java @@ -42,6 +42,8 @@ package jogamp.opengl.macosx.cgl; import javax.media.opengl.GLContext; import javax.media.opengl.GLException; +import jogamp.opengl.GLContextImpl; + public class MacOSXOnscreenCGLContext extends MacOSXCGLContext { public MacOSXOnscreenCGLContext(MacOSXOnscreenCGLDrawable drawable, @@ -72,8 +74,8 @@ public class MacOSXOnscreenCGLContext extends MacOSXCGLContext { } @Override - protected boolean createImpl() { - boolean res = super.createImpl(); + protected boolean createImpl(GLContextImpl sharedWith) { + boolean res = super.createImpl(sharedWith); lastWidth = -1; lastHeight = -1; if(res && isNSContext()) { diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXJava2DCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXJava2DCGLContext.java index ae58f6811..a9376fb34 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXJava2DCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXJava2DCGLContext.java @@ -44,6 +44,7 @@ import java.awt.Graphics; import javax.media.opengl.GLContext; import javax.media.opengl.GLException; +import jogamp.opengl.GLContextImpl; import jogamp.opengl.awt.Java2D; import jogamp.opengl.awt.Java2DGLContext; import jogamp.opengl.macosx.cgl.MacOSXCGLContext; @@ -79,8 +80,8 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL } } - protected boolean createImpl() { - long share = createImplPreset(); + protected boolean createImpl(GLContextImpl shareWith) { + long share = createImplPreset(shareWith); long ctx = Java2D.createOGLContextOnSurface(graphics, share); if (ctx == 0) { |