aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/classes')
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/DisplayImpl.java54
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java7
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/WindowImpl.java27
3 files changed, 45 insertions, 43 deletions
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;