summaryrefslogtreecommitdiffstats
path: root/src/newt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2019-12-05 17:42:02 +0100
committerSven Gothel <[email protected]>2019-12-05 17:42:02 +0100
commitd693425e2e74a5e4a80c3fde552ffc7d757330f1 (patch)
tree058e06e1a916498a8f30b3a8c573208c2d139139 /src/newt
parent033ee4cad3493038480b06f6caf3de015a3e8de7 (diff)
PointerIcon new instances are always valid ..
Move native handle check to pre-destruction call in PointerIconImpl.destroyOnEDT(..), unifying single destruction and all.
Diffstat (limited to 'src/newt')
-rw-r--r--src/newt/classes/jogamp/newt/DisplayImpl.java2
-rw-r--r--src/newt/classes/jogamp/newt/PointerIconImpl.java20
2 files changed, 15 insertions, 7 deletions
diff --git a/src/newt/classes/jogamp/newt/DisplayImpl.java b/src/newt/classes/jogamp/newt/DisplayImpl.java
index 7fdcb4d7d..8c0240ffd 100644
--- a/src/newt/classes/jogamp/newt/DisplayImpl.java
+++ b/src/newt/classes/jogamp/newt/DisplayImpl.java
@@ -96,7 +96,7 @@ public abstract class DisplayImpl extends Display {
if(DEBUG) {
System.err.println("destroyAllPointerIconFromList: dpy "+toHexString(dpy)+", # "+i+"/"+count+": "+item+" @ "+getThreadName());
}
- if( null != item && item.isValid() ) {
+ if( null != item ) {
item.destroyOnEDT(dpy);
}
}
diff --git a/src/newt/classes/jogamp/newt/PointerIconImpl.java b/src/newt/classes/jogamp/newt/PointerIconImpl.java
index e0a47fed2..57f613fea 100644
--- a/src/newt/classes/jogamp/newt/PointerIconImpl.java
+++ b/src/newt/classes/jogamp/newt/PointerIconImpl.java
@@ -55,6 +55,9 @@ public class PointerIconImpl implements PointerIcon {
this.pixels = pixels;
this.hotspot = hotspot;
this.handle=handle;
+ if( 0 == handle ) {
+ throw new IllegalArgumentException("0 native handle: "+this);
+ }
}
public PointerIconImpl(final DisplayImpl display, final PixelRectangle pixelrect, final PointImmutable hotspot, final long handle) {
this.display = display;
@@ -63,6 +66,9 @@ public class PointerIconImpl implements PointerIcon {
this.pixels = pixelrect.getPixels();
this.hotspot = hotspot;
this.handle=handle;
+ if( 0 == handle ) {
+ throw new IllegalArgumentException("0 native handle: "+this);
+ }
}
@Override
@@ -113,7 +119,7 @@ public class PointerIconImpl implements PointerIcon {
if(Display.DEBUG) {
System.err.println("PointerIcon.destroy: "+this+", "+display+", "+Display.getThreadName());
}
- if( 0 != handle ) {
+ if( 0 != handle ) { // early out
synchronized(display.pointerIconList) {
display.pointerIconList.remove(this);
}
@@ -126,14 +132,16 @@ public class PointerIconImpl implements PointerIcon {
}
}
- /** No checks, assume execution on EDT */
+ /** assume execution on EDT */
synchronized void destroyOnEDT(final long dpy) {
final long h = handle;
handle = 0;
- try {
- display.destroyPointerIconImpl(dpy, h);
- } catch (final Exception e) {
- e.printStackTrace();
+ if( 0 != h ) { // avoid double free
+ try {
+ display.destroyPointerIconImpl(dpy, h);
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
}
}