From cc64ad2b1f7904af4e7bd27e927e0bb331db782b Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 25 Jun 2013 07:04:17 +0200 Subject: NEWT WindowImpl/GLWindow: @ JVM Shutdown, force stop animation thread w/o blocking. --- .../classes/com/jogamp/newt/opengl/GLWindow.java | 20 ++++++++++++++++++++ src/newt/classes/jogamp/newt/WindowImpl.java | 17 ++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index 345d92bc1..25249cee4 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -34,6 +34,8 @@ package com.jogamp.newt.opengl; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.List; import javax.media.nativewindow.AbstractGraphicsConfiguration; @@ -529,6 +531,24 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind savedAnimator.resume(); } } + + @SuppressWarnings("deprecation") + @Override + public void shutdownRenderingAction() { + final GLAnimatorControl anim = GLWindow.this.getAnimator(); + if ( null != anim && anim.isAnimating() ) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + final Thread animThread = anim.getThread(); + if( null != animThread ) { + try { + animThread.stop(); + } catch(Throwable t) { } + } + return null; + } } ); + } + } } //---------------------------------------------------------------------- diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 6787f0ab3..77ff21061 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -88,7 +88,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer ScreenImpl.initSingleton(); } - /** Maybe utilized at a shutdown hook, impl. does not synchronize, however the Window destruction and EDT removal blocks. */ + /** Maybe utilized at a shutdown hook, impl. does not block. */ public static final void shutdownAll() { final int wCount = windowList.size(); if(DEBUG_IMPLEMENTATION) { @@ -99,7 +99,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer if(DEBUG_IMPLEMENTATION) { System.err.println("Window.shutdownAll["+(i+1)+"/"+wCount+"]: "+toHexString(w.getWindowHandle())); } - w.markInvalid(); + w.shutdown(); } } @@ -242,7 +242,10 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } /** Fast invalidation of instance w/o any blocking function call. */ - private final void markInvalid() { + private final void shutdown() { + if(null!=lifecycleHook) { + lifecycleHook.shutdownRenderingAction(); + } setWindowHandle(0); visible = false; fullscreen = false; @@ -310,6 +313,14 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer * @see #pauseRenderingAction() */ void resumeRenderingAction(); + + /** + * Shutdown rendering action (thread) abnormally. + *

+ * Should be called only at shutdown, if necessary. + *

+ */ + void shutdownRenderingAction(); } private boolean createNative() { -- cgit v1.2.3