diff options
author | Kenneth Russel <[email protected]> | 2005-05-10 17:47:31 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2005-05-10 17:47:31 +0000 |
commit | 7da326380ca234d31627c5eaa8e7eacd3bfb8a4d (patch) | |
tree | 0a827c1e1384f9b36e01fb314d9ee182bcfa23a2 /src/net | |
parent | ff22a4f5a17eac8402706993dd54f75b6fae0110 (diff) |
Fixed race conditions in Mac OS X onscreen context creation that
showed up after recent GLJPanel fix to clean up resource leaks.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@267 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net')
5 files changed, 37 insertions, 10 deletions
diff --git a/src/net/java/games/jogl/GLJPanel.java b/src/net/java/games/jogl/GLJPanel.java index 07399b978..155aca639 100644 --- a/src/net/java/games/jogl/GLJPanel.java +++ b/src/net/java/games/jogl/GLJPanel.java @@ -153,6 +153,9 @@ public final class GLJPanel extends JPanel implements GLDrawable { heavyweight.display(); pbuffer.display(); } catch (GLException e) { + if (DEBUG) { + e.printStackTrace(); + } // We consider any exception thrown during updating of the // heavyweight or pbuffer during the initialization phases // to be an indication that there was a problem @@ -436,13 +439,16 @@ public final class GLJPanel extends JPanel implements GLDrawable { pbufferInitializationCompleted = false; if (firstTime) { toplevel.add(heavyweight); - toplevel.setSize(0, 0); + toplevel.setSize(1, 1); } EventQueue.invokeLater(new Runnable() { public void run() { try { toplevel.setVisible(true); } catch (GLException e) { + if (DEBUG) { + e.printStackTrace(); + } disableHardwareRendering(); } } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXDummyGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXDummyGLContext.java index 9b8f02660..f32c8bb15 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXDummyGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXDummyGLContext.java @@ -106,7 +106,7 @@ class MacOSXDummyGLContext extends MacOSXGLContext throw new GLException("Should not call this"); } - protected void create() { + protected boolean create() { throw new GLException("Should not call this"); } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java index cfa5c3d99..684f82a53 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java @@ -121,7 +121,7 @@ public abstract class MacOSXGLContext extends GLContext * Creates and initializes an appropriate OpenGl nsContext. Should only be * called by {@link makeCurrent(Runnable)}. */ - protected void create() { + protected boolean create() { MacOSXGLContext other = (MacOSXGLContext) GLContextShareSet.getShareContext(this); long share = 0; if (other != null) { @@ -130,6 +130,7 @@ public abstract class MacOSXGLContext extends GLContext throw new GLException("GLContextShareSet returned an invalid OpenGL context"); } } + int[] viewNotReady = new int[1]; nsContext = CGL.createContext(share, nsView, capabilities.getDoubleBuffered() ? 1 : 0, @@ -144,18 +145,29 @@ public abstract class MacOSXGLContext extends GLContext capabilities.getAccumBlueBits(), capabilities.getAccumAlphaBits(), capabilities.getSampleBuffers() ? 1 : 0, - capabilities.getNumSamples()); + capabilities.getNumSamples(), + viewNotReady); if (nsContext == 0) { + if (viewNotReady[0] == 1) { + if (DEBUG) { + System.err.println("!!! View not ready for " + getClass().getName()); + } + // View not ready at the window system level -- this is OK + return false; + } throw new GLException("Error creating nsContext"); } //updater = CGL.updateContextRegister(nsContext, nsView); // gznote: not thread safe yet! GLContextShareSet.contextCreated(this); + return true; } protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { boolean created = false; if (nsContext == 0) { - create(); + if (!create()) { + return false; + } if (DEBUG) { System.err.println("!!! Created GL nsContext for " + getClass().getName()); } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java index 401a657fe..f28a302b1 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java @@ -131,6 +131,9 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext { (MacOSXPbufferGLContext) pbuffersToInstantiate.remove(pbuffersToInstantiate.size() - 1); ctx.createPbuffer(nsView, nsContext); } + } else { + // View might not have been ready + unlockSurface(); } return ret; } catch (RuntimeException e) { diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java index 8e65ce1f3..bc046bcc1 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java @@ -65,13 +65,13 @@ public class MacOSXPbufferGLContext extends MacOSXGLContext { renderTarget = GL.GL_TEXTURE_2D; } - this.pBuffer = CGL.createPBuffer(renderTarget, width, height); - if (this.pBuffer == 0) { + pBuffer = CGL.createPBuffer(renderTarget, width, height); + if (pBuffer == 0) { throw new GLException("pbuffer creation error: CGL.createPBuffer() failed"); } if (DEBUG) { - System.err.println("Created pbuffer " + width + " x " + height); + System.err.println("Created pbuffer 0x" + Long.toHexString(pBuffer) + ", " + width + " x " + height + " for " + this); } } @@ -79,6 +79,9 @@ public class MacOSXPbufferGLContext extends MacOSXGLContext { created = false; if (pBuffer == 0) { + if (DEBUG) { + System.err.println("Pbuffer not instantiated yet for " + this); + } // pbuffer not instantiated yet return false; } @@ -151,10 +154,13 @@ public class MacOSXPbufferGLContext extends MacOSXGLContext { return (1<<power); } - protected void create() { - super.create(); + protected boolean create() { + if (!super.create()) { + return false; + } created = true; // Must now associate the pbuffer with our newly-created context CGL.setContextPBuffer(nsContext, pBuffer); + return true; } } |