diff options
author | Sven Gothel <[email protected]> | 2010-09-26 02:02:59 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-09-26 02:02:59 +0200 |
commit | a831e7d5c5a9c1e82f70713f7d07946cfc562041 (patch) | |
tree | fc6d6b4fd2424ff2130858095613d18d426b7c60 | |
parent | bcad73dccb1cd0c32e3a77b3406ddc74e8f2e4ac (diff) |
NEWT: Fix destruction of not yet realized Window/Screen/Display ; Bug411 Test: Add parallel NEWT animation.
4 files changed, 65 insertions, 43 deletions
diff --git a/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWTUsageBeforeJOGLInitBug411.java b/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWTUsageBeforeJOGLInitBug411.java index 8f0216fe7..6dea35769 100644 --- a/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWTUsageBeforeJOGLInitBug411.java +++ b/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWTUsageBeforeJOGLInitBug411.java @@ -274,9 +274,19 @@ public class TestSwingAWTUsageBeforeJOGLInitBug411 { GLProfile glp = GLProfile.getDefault(); GLCapabilities caps = new GLCapabilities(glp); + GLWindow win0 = GLWindow.create(caps); + win0.setSize(100,100); + win0.setVisible(true); + win0.addGLEventListener(new Gears()); + Animator anim0 = new Animator(win0); + anim0.start(); + GLCanvas glCanvas = new GLCanvas(caps); runTestGL(glCanvas, glCanvas); + + anim0.stop(); + win0.destroy(true); } @Test @@ -284,10 +294,20 @@ public class TestSwingAWTUsageBeforeJOGLInitBug411 { GLProfile glp = GLProfile.getDefault(); GLCapabilities caps = new GLCapabilities(glp); + GLWindow win0 = GLWindow.create(caps); + win0.setSize(100,100); + win0.setVisible(true); + win0.addGLEventListener(new Gears()); + Animator anim0 = new Animator(win0); + anim0.start(); + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(GLWindow.create(caps)); runTestGL(newtCanvasAWT, (GLAutoDrawable)newtCanvasAWT.getNEWTChild()); newtCanvasAWT.destroy(true); + + anim0.stop(); + win0.destroy(true); } static int atoi(String a) { diff --git a/src/newt/classes/com/jogamp/newt/impl/DisplayImpl.java b/src/newt/classes/com/jogamp/newt/impl/DisplayImpl.java index 4f839ed42..894b9a201 100644 --- a/src/newt/classes/com/jogamp/newt/impl/DisplayImpl.java +++ b/src/newt/classes/com/jogamp/newt/impl/DisplayImpl.java @@ -157,35 +157,35 @@ public abstract class DisplayImpl extends Display { } public synchronized final void destroy() { - if ( null != aDevice ) { - if(DEBUG) { - dumpDisplayList("Display.destroy("+getFQName()+") BEGIN"); - } - synchronized(displayList) { - displayList.remove(this); - displaysActive--; - } - if(DEBUG) { - System.err.println("Display.destroy(): "+this+" "+getThreadName()); - } - final DisplayImpl f_dpy = this; - final EDTUtil f_edtUtil = edtUtil; - stopEDT( new Runnable() { - public void run() { + if(DEBUG) { + dumpDisplayList("Display.destroy("+getFQName()+") BEGIN"); + } + synchronized(displayList) { + displayList.remove(this); + displaysActive--; + } + if(DEBUG) { + System.err.println("Display.destroy(): "+this+" "+getThreadName()); + } + final AbstractGraphicsDevice f_aDevice = aDevice; + final DisplayImpl f_dpy = this; + stopEDT( new Runnable() { + public void run() { + if ( null != f_aDevice ) { f_dpy.closeNativeImpl(); } - } ); - if(null!=edtUtil) { - if ( DEBUG_TEST_EDT_MAINTHREAD ) { - MainThread.removePumpMessage(this); // JAU EDT Test .. - } - edtUtil.waitUntilStopped(); - edtUtil.reset(); } - aDevice = null; - if(DEBUG) { - dumpDisplayList("Display.destroy("+getFQName()+") END"); + } ); + if(null!=edtUtil) { + if ( DEBUG_TEST_EDT_MAINTHREAD ) { + MainThread.removePumpMessage(this); // JAU EDT Test .. } + edtUtil.waitUntilStopped(); + edtUtil.reset(); + } + aDevice = null; + if(DEBUG) { + dumpDisplayList("Display.destroy("+getFQName()+") END"); } } @@ -207,8 +207,8 @@ public abstract class DisplayImpl extends Display { if(DEBUG) { System.err.println("Display.removeReference() ("+DisplayImpl.getThreadName()+"): "+refCount+" -> "+(refCount-1)); } - refCount--; - if(0==refCount && destroyWhenUnused) { + refCount--; // could become < 0, in case of forced destruction without actual creation/addReference + if(0>=refCount && getDestroyWhenUnused()) { destroy(); } return refCount; diff --git a/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java b/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java index 0104b4a4c..1a76152f6 100644 --- a/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java +++ b/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java @@ -101,9 +101,10 @@ public abstract class ScreenImpl implements Screen { public synchronized final void destroy() { if ( null != aScreen ) { closeNativeImpl(); - display.removeReference(); aScreen = null; } + refCount = 0; + display.removeReference(); } protected synchronized final int addReference() { @@ -123,8 +124,8 @@ public abstract class ScreenImpl implements Screen { if(DEBUG) { System.err.println("Screen.removeReference() ("+DisplayImpl.getThreadName()+"): "+refCount+" -> "+(refCount-1)); } - refCount--; - if(0==refCount && getDestroyWhenUnused()) { + refCount--; // could become < 0, in case of forced destruction without actual creation/addReference + if(0>=refCount && getDestroyWhenUnused()) { destroy(); } return refCount; diff --git a/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java b/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java index 9111419fc..3939a12fb 100644 --- a/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java +++ b/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java @@ -179,6 +179,13 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer protected String title = "Newt Window"; protected boolean undecorated = false; + private final void destroyScreen() { + screenReferenced = false; + if(null!=screen) { + screen.removeReference(); + screen = null; + } + } private final void setScreen(ScreenImpl newScreen) { if(screenReferenced) { screenReferenced = false; @@ -506,15 +513,13 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } public void destroy(boolean unrecoverable) { - if(isValid()) { - if(DEBUG_IMPLEMENTATION) { - String msg = new String("Window.destroy(unrecoverable: "+unrecoverable+") START "+getThreadName()/*+", "+this*/); - System.err.println(msg); - //Exception ee = new Exception(msg); - //ee.printStackTrace(); - } - runOnEDTIfAvail(true, new DestroyAction(unrecoverable)); + if(DEBUG_IMPLEMENTATION) { + String msg = new String("Window.destroy(unrecoverable: "+unrecoverable+") START "+getThreadName()/*+", "+this*/); + System.err.println(msg); + //Exception ee = new Exception(msg); + //ee.printStackTrace(); } + runOnEDTIfAvail(true, new DestroyAction(unrecoverable)); } class DestroyAction implements Runnable { @@ -525,10 +530,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer public void run() { windowLock.lock(); try { - if( !isValid() ) { - return; // nop - } - // Childs first .. synchronized(childWindowsLock) { // avoid ConcurrentModificationException: parent -> child -> parent.removeChild(this) @@ -616,7 +617,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer fullscreen = false; if(unrecoverable) { - setScreen(null); + destroyScreen(); parentWindowHandle = 0; parentWindow = null; caps = null; |