aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util/Animator.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-09-23 03:56:04 +0200
committerSven Gothel <[email protected]>2014-09-23 03:56:04 +0200
commit66ecb6c386d5c3d87d8be2600a0c7dd7d71a4329 (patch)
tree8a50d67fb0f3ea895d2522a9888f585c3737b470 /src/jogl/classes/com/jogamp/opengl/util/Animator.java
parentc0c5fac5301f7264cfdd69117c1f85adfdc7b604 (diff)
Fix synchronization issues in Animator* Exception case
Refines commit cef7ba607ad7e8eb1ff2a438d77710a29aa0bda6 - The animator monitor-lock was still hold in the post finally block issuing flushGLRunnables(), due to intrinsic monitor release (in finally): - <http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html#jvms-2.11.10> - <http://stackoverflow.com/questions/10743285/behavior-of-a-synchronized-method-with-try-and-finally> - Further: AnimatorBase.flushGLRunnables() acquired the lock itself (duh!) This commit removes the requirement for finally altogether by simply return a boolean from handleUncaughtException(caughtException), where false denotes the caller to propagate the exception itself (no handler). Post synchronized block then issues flushGLRunnables() and exceptation propagation as required. AnimatorBase.flushGLRunnables() 'synchronized' modifier is removed. Further, ThreadDeath is being propagated if caught. Here the finally block is also removed - redundant.
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/Animator.java')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/Animator.java85
1 files changed, 44 insertions, 41 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/Animator.java b/src/jogl/classes/com/jogamp/opengl/util/Animator.java
index 4686e1745..03c566d7d 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/Animator.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/Animator.java
@@ -132,7 +132,8 @@ public class Animator extends AnimatorBase {
@Override
public void run() {
- UncaughtAnimatorException displayCaught = null;
+ ThreadDeath caughtThreadDeath = null;
+ UncaughtAnimatorException caughtException = null;
try {
synchronized (Animator.this) {
@@ -163,7 +164,7 @@ public class Animator extends AnimatorBase {
try {
display(); // propagate exclusive context -> off!
} catch (final UncaughtAnimatorException dre) {
- displayCaught = dre;
+ caughtException = dre;
stopIssued = true;
break; // end pause loop
}
@@ -196,7 +197,7 @@ public class Animator extends AnimatorBase {
try {
display();
} catch (final UncaughtAnimatorException dre) {
- displayCaught = dre;
+ caughtException = dre;
stopIssued = true;
break; // end animation loop
}
@@ -206,52 +207,54 @@ public class Animator extends AnimatorBase {
}
}
}
- } catch( final ThreadDeath td) {
+ } catch(final ThreadDeath td) {
if(DEBUG) {
System.err.println("Animator caught: "+td.getClass().getName()+": "+td.getMessage());
td.printStackTrace();
}
- } finally {
- if( exclusiveContext && !drawablesEmpty ) {
- setDrawablesExclCtxState(false);
- try {
- display(); // propagate exclusive context -> off!
- } catch (final UncaughtAnimatorException dre) {
- if( null == displayCaught ) {
- displayCaught = dre;
- } else {
- dre.printStackTrace();
- }
- }
- }
- boolean flushGLRunnables = false;
+ caughtThreadDeath = td;
+ }
+ if( exclusiveContext && !drawablesEmpty ) {
+ setDrawablesExclCtxState(false);
try {
- synchronized (Animator.this) {
- if(DEBUG) {
- System.err.println("Animator stop on " + animThread.getName() + ": " + toString());
- if( null != displayCaught ) {
- System.err.println("Animator caught: "+displayCaught.getMessage());
- displayCaught.printStackTrace();
- }
- }
- stopIssued = false;
- pauseIssued = false;
- isAnimating = false;
- try {
- if( null != displayCaught ) {
- flushGLRunnables = true;
- handleUncaughtException(displayCaught); // may throw exception if null handler
- }
- } finally {
- animThread = null;
- Animator.this.notifyAll();
- }
+ display(); // propagate exclusive context -> off!
+ } catch (final UncaughtAnimatorException dre) {
+ if( null == caughtException ) {
+ caughtException = dre;
+ } else {
+ System.err.println("Animator.setExclusiveContextThread: caught: "+dre.getMessage());
+ dre.printStackTrace();
}
- } finally {
- if( flushGLRunnables ) {
- flushGLRunnables();
+ }
+ }
+ boolean flushGLRunnables = false;
+ boolean throwCaughtException = false;
+ synchronized (Animator.this) {
+ if(DEBUG) {
+ System.err.println("Animator stop on " + animThread.getName() + ": " + toString());
+ if( null != caughtException ) {
+ System.err.println("Animator caught: "+caughtException.getMessage());
+ caughtException.printStackTrace();
}
}
+ stopIssued = false;
+ pauseIssued = false;
+ isAnimating = false;
+ if( null != caughtException ) {
+ flushGLRunnables = true;
+ throwCaughtException = !handleUncaughtException(caughtException);
+ }
+ animThread = null;
+ Animator.this.notifyAll();
+ }
+ if( flushGLRunnables ) {
+ flushGLRunnables();
+ }
+ if( throwCaughtException ) {
+ throw caughtException;
+ }
+ if( null != caughtThreadDeath ) {
+ throw caughtThreadDeath;
}
}
}