From 0f4826aff7b84698df7c465782c81102a6160a30 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Thu, 18 Nov 2004 23:06:11 +0000 Subject: Fixed Issue 22: GLException hides user exception The central try/finally cause in GLException.invokeGL() called GLContext.free() after catching and rethrowing the end user's exception from the GLEventListenerdisplay() routine, which caused the end user's exception to be overwritten with the internal GLException. Fixed this by initializing the cause of the internal exception, and also continuing to propagate out the end user's exception. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@171 232f8b59-042b-4e1e-8c03-345bb8c30851 --- src/net/java/games/jogl/impl/GLContext.java | 40 ++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'src/net/java') diff --git a/src/net/java/games/jogl/impl/GLContext.java b/src/net/java/games/jogl/impl/GLContext.java index 5a56bf9ee..443d009dc 100644 --- a/src/net/java/games/jogl/impl/GLContext.java +++ b/src/net/java/games/jogl/impl/GLContext.java @@ -280,7 +280,8 @@ public abstract class GLContext { ctxStack.push(this, initAction); } - boolean caughtException = false; + RuntimeException userException = null; + GLException internalException = null; try { if (deferredReshapeAction != null) { @@ -292,10 +293,10 @@ public abstract class GLContext { swapBuffers(); } } catch (RuntimeException e) { - caughtException = true; - throw(e); + userException = e; + throw(userException); } finally { - if (caughtException) { + if (userException != null) { // Disallow setRenderingThread if display action is throwing exceptions renderingThread = null; } @@ -316,13 +317,21 @@ public abstract class GLContext { System.err.println("Freeing context " + this); } - free(); + try { + free(); + } catch (GLException e) { + internalException = e; + } if (curContext != null) { if (DEBUG) { System.err.println("Making context " + curContext + " current again"); } - curContext.makeCurrent(curInitAction); + try { + curContext.makeCurrent(curInitAction); + } catch (GLException e) { + internalException = e; + } } } @@ -334,11 +343,28 @@ public abstract class GLContext { assert(savedPerThreadContext == curContext); ctxStack.pop(); if (savedPerThreadContext.getRenderingThread() == null) { - savedPerThreadContext.free(); + try { + savedPerThreadContext.free(); + } catch (GLException e) { + internalException = e; + } } else { setPerThreadSavedCurrentContext(savedPerThreadContext, savedPerThreadInitAction); } } + + // Make sure the end user's exception shows up in any stack + // traces; the rethrow of the userException above should take + // precedence if the internalException will otherwise squelch it + if (internalException != null) { + if (userException != null && + internalException.getCause() == null) { + internalException.initCause(userException); + throw(internalException); + } else if (userException == null) { + throw(internalException); + } + } } } -- cgit v1.2.3