Specify behavior of GLEventListener Exceptions occurring while GLAutoDrawable processing. We shall not suppress exceptions thrown while processing GLAutoDrawable in general. This may only be allowed while destruction, however, we might want to throw the first caught exception afterwards. GLDrawableHelper is suspicious of at least suppressing GLEventListener.init(..) exceptions, as well as within destruction. What shall happen if GLEventListener throws an exception during GLAutoDrawable.display(..) ? - Throw an exception What shall happen when using off-thread rendering, i.e. using an animator ? - Stop the animator - ... Maybe the animator, or better the GLAutoDrawable shall provide plugin-in an exception handler allowing the user application to react on off-thread GLExceptions.
Consistent Exception Behavior Spec - 1st draft GLDrawableHelper is used in all GLAutoDrawable implementations and for most operations. GLAutoDrawable/GLDrawableHelper invoke(..) method: - invoke(..) forwards a caught exception - if blocking, it forwards an exception happening within the passed GLRunnable(s). Here the exception is caught, printed and then thrown by invoke itself. - if non-blocking, an exception happening within the passed GLRunnable(s) will be thrown in the thread issuing it's execution, i.e. display() call. Here the exception is not caught and simply thrown by the GLRunnable. GLAutoDrawable.destroy() -> GLDrawableHelper.disposeGL(..) method: - disposeAllGLEventListener() being invoked by disposeGL(..), catches exception thrown by GLEventListener.dispose(..) and prints them to stderr. The first caught exception is re-thrown at the end as an GLException. - disposeGL() catches re-thrown GLException by disposeAllGLEventListener() for GLEventListener.dispose(..) and re-throws it when operation is complete. - disposeGL() catches an exception thrown at context destruction or release and re-throws it when operation is complete. An early exception at context.makeCurrent() is _not_ caught, since it is the first operation which simply shall unwind the stack. GLAutoDrawable.display() -> GLDrawableHelper.invokeGLImpl(..) method: - invokeGLImpl(..) for display() follows disposeGL() mechanism, i.e. it catches exception thrown at GLEventListener's init(..), reshape(..) and display(..) methods and re-throws it when operation is complete. It also catches an exception thrown at context release and re-throws it when operation is complete. An early exception at context.makeCurrent() is _not_ caught, since it is the first operation which simply shall unwind the stack. ++++ None of the above thrown exception shall be caught and suppressed on the caller side. If an operation must be completed while an exception is caught, it shall be cached and re-thrown after the operations. In case multiple exception at multiple places are caught within an operation, they all shall be cached and the first one shall be re-thrown. In case of multiple exception from the same place, i.e. a loop through all GLEventListener, the first shall be cached and re-thrown after operation is completed. It has to be determined, whether we like to dump the exceptions, especially the ones who get suppressed in case of multiple exceptions. +++ In case off-thread operations cause an exception, an exception handler shall be able to be installed, e.g. within GLAutoDrawable or an Animator object. The latter might be more suitable, since it installs a handler within the multithreaded manager. Since GLAnimatorControl is attached to GLAutoDrawable, we might have good solution here.
ba1ffe66697c3175b423cb7ab9b686d73959708d Implements spec as described in comment 1 TODO: Offthread exception handler
60f397da5fd27e2140a0c1b3a102bba0e67c9f19 Fix NPE regression of commit ba1ffe66697c3175b423cb7ab9b686d73959708d
(In reply to comment #2) > > TODO: Offthread exception handler Good idea. I agree with this suggestion.
In case of an exception thrown within an GLEventListener called off-thread by Animator: - Animator shall stop - Animator shall forward the exception GLDrawableHelper shall also flush all queued GLRunnable tasks in case of an exception, so that another thread waiting until it's completion is notified and continues processing.
07a4801f3b5bfd4fba9a1a4a542ce2f2eae4396a Implements behavior of comment 5
commit 88eef9e4eae8e63762252f1d11bca2bd0fde809b: Add GLAnimatorControl.UncaughtGLAnimatorExceptionHandler interface to optionally handle uncaught exception within an animator thread by the user. Implementation also requires to flush all enqueued GLRunnable instances via GLAutoDrawable.invoked(..) in case such exception occurs. Hence 'GLAutoDrawable.flushGLRunnables()' has been added. Only subsequent exceptions, which cannot be thrown are dumped to System.stderr. +++ Handling of exceptions during dispose() Exception in NEWT's disposeGL*() are also caught and re-thrown after the NEWT window has been destroyed in WindowImpl.destroyAction: - GLEventListener.dispose(..) - GLDrawableHelper.disposeAllGLEventListener(..) - GLDrawableHelper.disposeGL(..) - GLAutoDrawableBase.destroyImplInLock(..) - GLWindow.GLLifecycleHook.destroyActionInLock(..) - WindowImpl.destroyAction on NEWT-EDT - WindowImpl.destroy Further more, exceptions occuring in native windowing toolkit triggered destroy() are ignored: - GLAutoDrawableBase.defaultWindowDestroyNotifyOp(..) It has to be seen whether such exception handling for dispose() shall be added to AWT/SWT. +++ TestGLException01NEWT covers all GLEventListener exception cases on-thread and off-thread (via animator). +++
commit 5c1214b26ad6c877a9c0f8099a7fc2a230a8b245: Rename GLAnimatorControl.UncaughtGLAnimatorExceptionHandler to GLAnimatorControl.UncaughtExceptionHandler for simplicity.