From ee5c34e5bb067631572a7001ab1ec3543c52065f Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 17 Aug 2012 13:47:48 +0200 Subject: Robostness: GLDrawableImpl's contextMadeCurrent()/contextRealized() ; GLFBODrawableImpl.contextMadeCurrent(false), OffscreenAutoDrawable.setSize(..) GLDrawableImpl's contextMadeCurrent()/contextRealized(): - Catch exception which may appear during callback and cont. w/ GLContextImpl's release()/destroy() while throwing catched exception at end. GLFBODrawableImpl.contextMadeCurrent(false): - Detect null Colorbuffer ASAP and throw exception OffscreenAutoDrawable.setSize(..): - Catch exceptions at 1) GLFBODrawableImpl.setSize(..) and 2) GLContext.release() .. throw it in proper order. --- src/jogl/classes/jogamp/opengl/GLContextImpl.java | 21 +++++++++++++++++++-- .../classes/jogamp/opengl/GLFBODrawableImpl.java | 6 +++++- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'src/jogl/classes/jogamp') diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java index bf6a0ee6e..e82756022 100644 --- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java @@ -266,11 +266,16 @@ public abstract class GLContextImpl extends GLContext { if ( !lock.isOwner(Thread.currentThread()) ) { throw new GLException("Context not current on current thread "+Thread.currentThread().getName()+": "+this); } + Throwable drawableContextMadeCurrentException = null; final boolean actualRelease = ( inDestruction || lock.getHoldCount() == 1 ) && 0 != contextHandle; try { if( actualRelease ) { if( !inDestruction ) { - drawable.contextMadeCurrent(this, false); + try { + drawable.contextMadeCurrent(this, false); + } catch (Throwable t) { + drawableContextMadeCurrentException = t; + } } releaseImpl(); } @@ -285,6 +290,10 @@ public abstract class GLContextImpl extends GLContext { System.err.println(getThreadName() +": GLContext.ContextSwitch: obj " + toHexString(hashCode()) + ", ctx "+toHexString(contextHandle)+" - "+(actualRelease?"switch":"keep ")+" - CONTEXT_RELEASE - "+lock); } } + if(null != drawableContextMadeCurrentException) { + throw new GLException("GLContext.release(false) during GLDrawableImpl.contextMadeCurrent(this, false)", drawableContextMadeCurrentException); + } + } protected abstract void releaseImpl() throws GLException; @@ -300,6 +309,7 @@ public abstract class GLContextImpl extends GLContext { // this would be odd .. throw new GLException("Surface not ready to lock: "+drawable); } + Throwable drawableContextRealizedException = null; try { // Must hold the lock around the destroy operation to make sure we // don't destroy the context while another thread renders to it. @@ -320,7 +330,11 @@ public abstract class GLContextImpl extends GLContext { // needs current context to disable debug handler makeCurrent(); } - drawable.contextRealized(this, false); + try { + drawable.contextRealized(this, false); + } catch (Throwable t) { + drawableContextRealizedException = t; + } glDebugHandler.enable(false); if(lock.getHoldCount() > 1) { // pending release() after makeCurrent() @@ -343,6 +357,9 @@ public abstract class GLContextImpl extends GLContext { } finally { drawable.unlockSurface(); } + if(null != drawableContextRealizedException) { + throw new GLException("GLContext.destroy() during GLDrawableImpl.contextRealized(this, false)", drawableContextRealizedException); + } } resetStates(); } diff --git a/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java b/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java index b7ea4f826..03bc26cbc 100644 --- a/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java @@ -69,8 +69,12 @@ public class GLFBODrawableImpl extends GLDrawableImpl { fbo.bind(gl); } else { fbo.unbind(gl); + final TextureAttachment attachment = samples > 0 ? fbo.getSamplingSink() : (TextureAttachment) fbo.getColorbuffer(0) ; + if(null == attachment) { + throw new GLException("Null texture colorbuffer, samples "+samples+", "+fbo.toString()); + } gl.glActiveTexture(GL.GL_TEXTURE0 + texUnit); - fbo.use(gl, samples > 0 ? fbo.getSamplingSink() : (TextureAttachment) fbo.getColorbuffer(0) ); + fbo.use(gl, attachment ); if( samples > 0) { gl.glBindFramebuffer(GL2GL3.GL_READ_FRAMEBUFFER, fbo.getReadFramebuffer()); } -- cgit v1.2.3