From a831e7d5c5a9c1e82f70713f7d07946cfc562041 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 26 Sep 2010 02:02:59 +0200 Subject: NEWT: Fix destruction of not yet realized Window/Screen/Display ; Bug411 Test: Add parallel NEWT animation. --- .../classes/com/jogamp/newt/impl/DisplayImpl.java | 54 +++++++++++----------- .../classes/com/jogamp/newt/impl/ScreenImpl.java | 7 +-- .../classes/com/jogamp/newt/impl/WindowImpl.java | 27 +++++------ 3 files changed, 45 insertions(+), 43 deletions(-) (limited to 'src/newt/classes/com') 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; -- cgit v1.2.3