aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-10-02 07:28:00 +0200
committerSven Gothel <[email protected]>2012-10-02 07:28:00 +0200
commit7c333e3e2574879465719ed968112b27255368d4 (patch)
treef9c81117469fe10d23c106bb46151a3451169e3f
parent0790108ca9c2a6a6d494e5017589fe083c518e23 (diff)
Relax Bug 613 workaround of commit 92398025abdabb2fdef0d78edd41e730991a6f94
Utilizing a GlobalToolkitLock in general to lock the display connection results in deadlock situations where locked surfaces signal other [offscreen] surfaces to render. We have to see whether we find a better solution, for now sporadic XCB assertion still happen. But it is preferrable to point to the root cause, then to jumping through hoops to complicate locking or even to deadlock. Locking: - X11GLXGraphicsConfigurationFactory add missing device locking in: - getAvailableCapabilities - chooseGraphicsConfigurationStatic - Newt/X11Window: Discard display events after window close. Relax ATI XCB/threading bug workaround: - ToolkitProperties: requiresGlobalToolkitLock() -> hasThreadingIssues() - NativeWindowFactory: Don't use GlobalToolkitLock in case of 'threadingIssues' the impact is too severe (see above) - NativeWindowFactory: Add getGlobalToolkitLockIfRequired(): To be used for small code blocks. If having 'threadingIssues' a GlobalToolkitLock is returned, otherwise NullToolkitLock. - X11GLXContext: [create/destroy]ContextARBImpl: Use 'NativeWindowFactory.getGlobalToolkitLockIfRequired()' for extra locking Misc Cleanup: - *DrawableFactory createMutableSurface: Also create new device if type is not suitable - *DrawableFactory createDummySurfaceImpl: Pass chosenCaps and use it (preserves orig. requested user caps)
-rw-r--r--src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java9
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java8
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java9
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java13
-rw-r--r--src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java24
-rw-r--r--src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java22
-rw-r--r--src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java41
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java2
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java40
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/GlobalToolkitLock.java13
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java5
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/ToolkitProperties.java8
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java3
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java2
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java2
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java10
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java2
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java2
-rw-r--r--src/newt/native/X11Display.c4
-rw-r--r--src/newt/native/X11Window.c2
20 files changed, 113 insertions, 108 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java b/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
index bd2db1b81..0ea565b89 100644
--- a/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
@@ -188,7 +188,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
}
if( chosenCaps.isFBO() && isFBOAvailable ) {
// need to hook-up a native dummy surface since source may not have
- final ProxySurface dummySurface = createDummySurfaceImpl(adevice, true, chosenCaps, null, 64, 64);
+ final ProxySurface dummySurface = createDummySurfaceImpl(adevice, false, chosenCaps, (GLCapabilitiesImmutable)config.getRequestedCapabilities(), null, 64, 64);
dummySurface.setUpstreamSurfaceHook(new DelegatedUpstreamSurfaceHookWithSurfaceSize(dummySurface.getUpstreamSurfaceHook(), target));
result = createFBODrawableImpl(dummySurface, chosenCaps, 0);
} else {
@@ -299,7 +299,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
if( capsChosen.isFBO() ) {
device.lock();
try {
- final ProxySurface dummySurface = createDummySurfaceImpl(device, true, capsRequested, null, width, height);
+ final ProxySurface dummySurface = createDummySurfaceImpl(device, true, capsChosen, capsRequested, null, width, height);
final GLDrawableImpl dummyDrawable = createOnscreenDrawableImpl(dummySurface);
return new GLFBODrawableImpl.ResizeableImpl(this, dummyDrawable, dummySurface, capsChosen, 0);
} finally {
@@ -370,7 +370,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
}
device.lock();
try {
- return createDummySurfaceImpl(device, true, requestedCaps, chooser, width, height);
+ return createDummySurfaceImpl(device, true, requestedCaps, requestedCaps, chooser, width, height);
} finally {
device.unlock();
}
@@ -386,6 +386,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
* @param device a valid platform dependent target device.
* @param createNewDevice if <code>true</code> a new device instance is created using <code>device</code> details,
* otherwise <code>device</code> instance is used as-is.
+ * @param chosenCaps
* @param requestedCaps
* @param chooser the custom chooser, may be null for default
* @param width the initial width as returned by {@link NativeSurface#getWidth()}, not the actual dummy surface width.
@@ -395,7 +396,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
* @return the created {@link ProxySurface} instance w/o defined surface handle but platform specific {@link UpstreamSurfaceHook}.
*/
public abstract ProxySurface createDummySurfaceImpl(AbstractGraphicsDevice device, boolean createNewDevice,
- GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height);
+ GLCapabilitiesImmutable chosenCaps, GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height);
//---------------------------------------------------------------------------
//
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java
index a907c4aff..da3907193 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java
@@ -367,7 +367,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl {
if( hasPBuffer[0] ) {
// 2nd case create defaultDevice shared resource using pbuffer surface
- surface = createDummySurfaceImpl(eglDevice, false, reqCapsPBuffer, null, 64, 64); // egl pbuffer offscreen
+ surface = createDummySurfaceImpl(eglDevice, false, reqCapsPBuffer, reqCapsPBuffer, null, 64, 64); // egl pbuffer offscreen
upstreamSurface = (ProxySurface)surface;
upstreamSurface.createNotify();
deviceFromUpstreamSurface = false;
@@ -664,7 +664,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl {
GLCapabilitiesChooser chooser, UpstreamSurfaceHook upstreamHook) {
final boolean ownDevice;
final EGLGraphicsDevice device;
- if(createNewDevice || ! ( deviceReq instanceof EGLGraphicsDevice ) ) {
+ if( createNewDevice || ! (deviceReq instanceof EGLGraphicsDevice) ) {
final long nativeDisplayID = ( deviceReq instanceof EGLGraphicsDevice) ?
( (EGLGraphicsDevice) deviceReq ).getNativeDisplayID() : deviceReq.getHandle() ;
device = EGLDisplayUtil.eglCreateEGLGraphicsDevice(nativeDisplayID, deviceReq.getConnection(), deviceReq.getUnitID());
@@ -683,8 +683,8 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl {
@Override
public final ProxySurface createDummySurfaceImpl(AbstractGraphicsDevice deviceReq, boolean createNewDevice,
- GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
- final GLCapabilitiesImmutable chosenCaps = GLGraphicsConfigurationUtil.fixOffscreenBitOnly(requestedCaps); // complete validation in EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(..) above
+ GLCapabilitiesImmutable chosenCaps, GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
+ chosenCaps = GLGraphicsConfigurationUtil.fixOffscreenBitOnly(chosenCaps); // complete validation in EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(..) above
return createMutableSurfaceImpl(deviceReq, createNewDevice, chosenCaps, requestedCaps, chooser, new EGLDummyUpstreamSurfaceHook(width, height));
}
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
index d59197e1d..ec3156f52 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
@@ -226,7 +226,8 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl {
if (null == glp) {
throw new GLException("Couldn't get default GLProfile for device: "+sharedDevice);
}
- final GLDrawableImpl sharedDrawable = createOnscreenDrawableImpl(createDummySurfaceImpl(sharedDevice, false, new GLCapabilities(glp), null, 64, 64));
+ final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
+ final GLDrawableImpl sharedDrawable = createOnscreenDrawableImpl(createDummySurfaceImpl(sharedDevice, false, caps, caps, null, 64, 64));
sharedDrawable.setRealized(true);
final MacOSXCGLContext sharedContext = (MacOSXCGLContext) sharedDrawable.createContext(null);
@@ -358,7 +359,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl {
GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested,
GLCapabilitiesChooser chooser, UpstreamSurfaceHook upstreamHook) {
final MacOSXGraphicsDevice device;
- if(createNewDevice) {
+ if( createNewDevice || !(deviceReq instanceof MacOSXGraphicsDevice) ) {
device = new MacOSXGraphicsDevice(deviceReq.getUnitID());
} else {
device = (MacOSXGraphicsDevice)deviceReq;
@@ -373,8 +374,8 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl {
@Override
public final ProxySurface createDummySurfaceImpl(AbstractGraphicsDevice deviceReq, boolean createNewDevice,
- GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
- final GLCapabilitiesImmutable chosenCaps = GLGraphicsConfigurationUtil.fixOnscreenGLCapabilities(requestedCaps);
+ GLCapabilitiesImmutable chosenCaps, GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
+ chosenCaps = GLGraphicsConfigurationUtil.fixOnscreenGLCapabilities(chosenCaps);
return createMutableSurfaceImpl(deviceReq, createNewDevice, chosenCaps, requestedCaps, chooser,
new OSXDummyUpstreamSurfaceHook(width, height));
}
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
index 91d5c225a..c6bc61a27 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
@@ -318,7 +318,8 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
if (null == glp) {
throw new GLException("Couldn't get default GLProfile for device: "+sharedDevice);
}
- final GLDrawableImpl sharedDrawable = createOnscreenDrawableImpl(createDummySurfaceImpl(sharedDevice, false, new GLCapabilities(glp), null, 64, 64));
+ final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
+ final GLDrawableImpl sharedDrawable = createOnscreenDrawableImpl(createDummySurfaceImpl(sharedDevice, false, caps, caps, null, 64, 64));
sharedDrawable.setRealized(true);
final GLContextImpl sharedContext = (GLContextImpl) sharedDrawable.createContext(null);
@@ -543,7 +544,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested,
GLCapabilitiesChooser chooser, UpstreamSurfaceHook upstreamHook) {
final WindowsGraphicsDevice device;
- if(createNewDevice) {
+ if(createNewDevice || !(deviceReq instanceof WindowsGraphicsDevice)) {
device = new WindowsGraphicsDevice(deviceReq.getConnection(), deviceReq.getUnitID());
} else {
device = (WindowsGraphicsDevice)deviceReq;
@@ -558,18 +559,18 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
@Override
public final ProxySurface createDummySurfaceImpl(AbstractGraphicsDevice deviceReq, boolean createNewDevice,
- GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
+ GLCapabilitiesImmutable chosenCaps, GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
final WindowsGraphicsDevice device;
- if(createNewDevice) {
+ if( createNewDevice || !(deviceReq instanceof WindowsGraphicsDevice) ) {
device = new WindowsGraphicsDevice(deviceReq.getConnection(), deviceReq.getUnitID());
} else {
device = (WindowsGraphicsDevice)deviceReq;
}
final AbstractGraphicsScreen screen = new DefaultGraphicsScreen(device, 0);
- final GLCapabilitiesImmutable chosenCaps = GLGraphicsConfigurationUtil.fixOnscreenGLCapabilities(requestedCaps);
+ chosenCaps = GLGraphicsConfigurationUtil.fixOnscreenGLCapabilities(chosenCaps);
final WindowsWGLGraphicsConfiguration config = WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(chosenCaps, requestedCaps, chooser, screen);
if(null == config) {
- throw new GLException("Choosing GraphicsConfiguration failed w/ "+requestedCaps+" on "+screen);
+ throw new GLException("Choosing GraphicsConfiguration failed w/ "+chosenCaps+" on "+screen);
}
return new GDISurface(config, 0, new GDIDummyUpstreamSurfaceHook(width, height), createNewDevice);
}
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java
index 72ddd2693..f7389d42e 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java
@@ -48,6 +48,8 @@ import java.util.Map;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.nativewindow.ToolkitLock;
import javax.media.opengl.GLCapabilitiesImmutable;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLException;
@@ -180,11 +182,16 @@ public abstract class X11GLXContext extends GLContextImpl {
@Override
protected void destroyContextARBImpl(long ctx) {
- X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeSurface().getGraphicsConfiguration();
- long display = config.getScreen().getDevice().getHandle();
-
- glXMakeContextCurrent(display, 0, 0, 0);
- GLX.glXDestroyContext(display, ctx);
+ final ToolkitLock tkLock = NativeWindowFactory.getGlobalToolkitLockIfRequired();
+ tkLock.lock();
+ try {
+ long display = drawable.getNativeSurface().getDisplayHandle();
+
+ glXMakeContextCurrent(display, 0, 0, 0);
+ GLX.glXDestroyContext(display, ctx);
+ } finally {
+ tkLock.unlock();
+ }
}
private static final int ctx_arb_attribs_idx_major = 0;
private static final int ctx_arb_attribs_idx_minor = 2;
@@ -243,6 +250,8 @@ public abstract class X11GLXContext extends GLContextImpl {
AbstractGraphicsDevice device = config.getScreen().getDevice();
final long display = device.getHandle();
+ final ToolkitLock tkLock = NativeWindowFactory.getGlobalToolkitLockIfRequired();
+ tkLock.lock();
try {
// critical path, a remote display might not support this command,
// hence we need to catch the X11 Error within this block.
@@ -253,7 +262,10 @@ public abstract class X11GLXContext extends GLContextImpl {
Throwable t = new Throwable(getThreadName()+": Info: X11GLXContext.createContextARBImpl glXCreateContextAttribsARB failed with "+getGLVersion(major, minor, ctp, "@creation"), re);
t.printStackTrace();
}
+ } finally {
+ tkLock.unlock();
}
+
if(0!=ctx) {
if (!glXMakeContextCurrent(display, drawable.getHandle(), drawableRead.getHandle(), ctx)) {
if(DEBUG) {
@@ -420,7 +432,7 @@ public abstract class X11GLXContext extends GLContextImpl {
@Override
protected void destroyImpl() throws GLException {
- GLX.glXDestroyContext(drawable.getNativeSurface().getDisplayHandle(), contextHandle);
+ destroyContextARBImpl(contextHandle);
}
@Override
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
index 018f6a6ea..e38aabef8 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
@@ -229,7 +229,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
@Override
public SharedResourceRunner.Resource createSharedResource(String connection) {
- final X11GraphicsDevice sharedDevice = new X11GraphicsDevice(X11Util.openDisplay(connection), AbstractGraphicsDevice.DEFAULT_UNIT, true);
+ final X11GraphicsDevice sharedDevice = new X11GraphicsDevice(X11Util.openDisplay(connection), AbstractGraphicsDevice.DEFAULT_UNIT, true /* owner */);
sharedDevice.lock();
try {
final X11GraphicsScreen sharedScreen = new X11GraphicsScreen(sharedDevice, sharedDevice.getDefaultScreen());
@@ -246,8 +246,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
if (null == glp) {
throw new GLException("Couldn't get default GLProfile for device: "+sharedDevice);
}
-
- final GLDrawableImpl sharedDrawable = createOnscreenDrawableImpl(createDummySurfaceImpl(sharedDevice, false, new GLCapabilities(glp), null, 64, 64));
+
+ final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
+ final GLDrawableImpl sharedDrawable = createOnscreenDrawableImpl(createDummySurfaceImpl(sharedDevice, false, caps, caps, null, 64, 64));
sharedDrawable.setRealized(true);
final GLContextImpl sharedContext = (GLContextImpl) sharedDrawable.createContext(null);
@@ -499,11 +500,10 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
GLCapabilitiesImmutable capsRequested,
GLCapabilitiesChooser chooser, UpstreamSurfaceHook upstreamHook) {
final X11GraphicsDevice device;
- if(createNewDevice) {
- // Null X11 resource locking, due to private non-shared Display handle
- device = new X11GraphicsDevice(X11Util.openDisplay(deviceReq.getConnection()), deviceReq.getUnitID(), true);
+ if( createNewDevice || !(deviceReq instanceof X11GraphicsDevice) ) {
+ device = new X11GraphicsDevice(X11Util.openDisplay(deviceReq.getConnection()), deviceReq.getUnitID(), true /* owner */);
} else {
- device = (X11GraphicsDevice)deviceReq;
+ device = (X11GraphicsDevice) deviceReq;
}
final X11GraphicsScreen screen = new X11GraphicsScreen(device, device.getDefaultScreen());
final X11GLXGraphicsConfiguration config = X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, screen, VisualIDHolder.VID_UNDEFINED);
@@ -512,17 +512,17 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
}
return new WrappedSurface(config, 0, upstreamHook, createNewDevice);
}
-
+
@Override
public final ProxySurface createDummySurfaceImpl(AbstractGraphicsDevice deviceReq, boolean createNewDevice,
- GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
- final GLCapabilitiesImmutable chosenCaps = GLGraphicsConfigurationUtil.fixOnscreenGLCapabilities(requestedCaps);
+ GLCapabilitiesImmutable chosenCaps, GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
+ chosenCaps = GLGraphicsConfigurationUtil.fixOnscreenGLCapabilities(chosenCaps);
return createMutableSurfaceImpl(deviceReq, createNewDevice, chosenCaps, requestedCaps, chooser, new X11DummyUpstreamSurfaceHook(width, height));
}
@Override
protected final ProxySurface createProxySurfaceImpl(AbstractGraphicsDevice deviceReq, int screenIdx, long windowHandle, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, UpstreamSurfaceHook upstream) {
- final X11GraphicsDevice device = new X11GraphicsDevice(X11Util.openDisplay(deviceReq.getConnection()), deviceReq.getUnitID(), true);
+ final X11GraphicsDevice device = new X11GraphicsDevice(X11Util.openDisplay(deviceReq.getConnection()), deviceReq.getUnitID(), true /* owner */);
final X11GraphicsScreen screen = new X11GraphicsScreen(device, screenIdx);
final int xvisualID = X11Lib.GetVisualIDFromWindow(device.getHandle(), windowHandle);
if(VisualIDHolder.VID_UNDEFINED == xvisualID) {
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java
index ef2d3283d..8ac324205 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java
@@ -127,16 +127,22 @@ public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationF
throw new GLException("Shared resource for device n/a: "+device);
}
final X11GraphicsScreen sharedScreen = (X11GraphicsScreen) sharedResource.getScreen();
- final boolean isMultisampleAvailable = factory.isGLXMultisampleAvailable(sharedScreen.getDevice());
+ final X11GraphicsDevice sharedDevice = (X11GraphicsDevice) sharedScreen.getDevice();
+ final boolean isMultisampleAvailable = sharedResource.isGLXMultisampleAvailable();
final GLProfile glp = GLProfile.getDefault(device);
List<GLCapabilitiesImmutable> availableCaps = null;
-
- if( sharedResource.isGLXVersionGreaterEqualOneThree() ) {
- availableCaps = getAvailableGLCapabilitiesFBConfig(sharedScreen, glp, isMultisampleAvailable);
- }
- if( null == availableCaps || availableCaps.isEmpty() ) {
- availableCaps = getAvailableGLCapabilitiesXVisual(sharedScreen, glp, isMultisampleAvailable);
+
+ sharedDevice.lock();
+ try {
+ if( sharedResource.isGLXVersionGreaterEqualOneThree() ) {
+ availableCaps = getAvailableGLCapabilitiesFBConfig(sharedScreen, glp, isMultisampleAvailable);
+ }
+ if( null == availableCaps || availableCaps.isEmpty() ) {
+ availableCaps = getAvailableGLCapabilitiesXVisual(sharedScreen, glp, isMultisampleAvailable);
+ }
+ } finally {
+ sharedDevice.unlock();
}
if( null != availableCaps && availableCaps.size() > 1 ) {
Collections.sort(availableCaps, XVisualIDComparator);
@@ -215,16 +221,21 @@ public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationF
capsChosen = GLGraphicsConfigurationUtil.fixGLCapabilities( capsChosen, factory, x11Device);
final boolean usePBuffer = !capsChosen.isOnscreen() && capsChosen.isPBuffer();
-
+
X11GLXGraphicsConfiguration res = null;
- if( factory.isGLXVersionGreaterEqualOneThree(x11Device) ) {
- res = chooseGraphicsConfigurationFBConfig(capsChosen, capsReq, chooser, x11Screen, xvisualID);
- }
- if(null==res) {
- if(usePBuffer) {
- throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration based on FBConfig for visualID "+toHexString(xvisualID)+", "+capsChosen);
+ x11Device.lock();
+ try {
+ if( factory.isGLXVersionGreaterEqualOneThree(x11Device) ) {
+ res = chooseGraphicsConfigurationFBConfig(capsChosen, capsReq, chooser, x11Screen, xvisualID);
+ }
+ if(null==res) {
+ if(usePBuffer) {
+ throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration based on FBConfig for visualID "+toHexString(xvisualID)+", "+capsChosen);
+ }
+ res = chooseGraphicsConfigurationXVisual(capsChosen, capsReq, chooser, x11Screen, xvisualID);
}
- res = chooseGraphicsConfigurationXVisual(capsChosen, capsReq, chooser, x11Screen, xvisualID);
+ } finally {
+ x11Device.unlock();
}
if(null==res) {
throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration based on FBConfig and XVisual for visualID "+toHexString(xvisualID)+", "+x11Screen+", "+capsChosen);
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java
index 1cc796086..7be747ff5 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java
@@ -210,7 +210,7 @@ public class SWTAccessor {
if( null != OS_gtk_class ) {
long widgedHandle = callStaticMethodL2L(OS_GTK_WIDGET_WINDOW, handle);
long displayHandle = callStaticMethodL2L(OS_gdk_x11_drawable_get_xdisplay, widgedHandle);
- return new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT, false);
+ return new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT, false /* owner */);
}
final String nwt = NativeWindowFactory.getNativeWindowType(false);
if( NativeWindowFactory.TYPE_WINDOWS == nwt ) {
diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
index 1962bcd09..006ee4c97 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
@@ -42,6 +42,7 @@ import java.util.HashMap;
import java.util.Map;
import jogamp.nativewindow.Debug;
+import jogamp.nativewindow.GlobalToolkitLock;
import jogamp.nativewindow.NativeWindowFactoryImpl;
import jogamp.nativewindow.ToolkitProperties;
import jogamp.nativewindow.ResourceToolkitLock;
@@ -102,7 +103,7 @@ public abstract class NativeWindowFactory {
private static ToolkitLock jawtUtilJAWTToolkitLock;
private static boolean requiresToolkitLock;
- private static boolean requiresGlobalToolkitLock;
+ private static boolean desktopHasThreadingIssues;
private static volatile boolean isJVMShuttingDown = false;
@@ -183,15 +184,11 @@ public abstract class NativeWindowFactory {
final Boolean res1 = (Boolean) ReflectionUtil.callStaticMethod(clazzName, "requiresToolkitLock", null, null, cl);
requiresToolkitLock = res1.booleanValue();
- if(requiresToolkitLock) {
- final Boolean res2 = (Boolean) ReflectionUtil.callStaticMethod(clazzName, "requiresGlobalToolkitLock", null, null, cl);
- requiresGlobalToolkitLock = res2.booleanValue();
- } else {
- requiresGlobalToolkitLock = false;
- }
+ final Boolean res2 = (Boolean) ReflectionUtil.callStaticMethod(clazzName, "hasThreadingIssues", null, null, cl);
+ desktopHasThreadingIssues = res2.booleanValue();
} else {
requiresToolkitLock = false;
- requiresGlobalToolkitLock = false;
+ desktopHasThreadingIssues = false;
}
}
@@ -293,7 +290,7 @@ public abstract class NativeWindowFactory {
}
if(DEBUG) {
- System.err.println("NativeWindowFactory requiresToolkitLock "+requiresToolkitLock+", requiresGlobalToolkitLock "+requiresGlobalToolkitLock);
+ System.err.println("NativeWindowFactory requiresToolkitLock "+requiresToolkitLock+", desktopHasThreadingIssues "+desktopHasThreadingIssues);
System.err.println("NativeWindowFactory isAWTAvailable "+isAWTAvailable+", defaultFactory "+factory);
}
@@ -329,11 +326,6 @@ public abstract class NativeWindowFactory {
return requiresToolkitLock;
}
- /** @return true if the underlying toolkit requires global locking, otherwise false. */
- public static boolean requiresGlobalToolkitLock() {
- return requiresGlobalToolkitLock;
- }
-
/** @return true if not headless, AWT Component and NativeWindow's AWT part available */
public static boolean isAWTAvailable() { return isAWTAvailable; }
@@ -382,12 +374,16 @@ public abstract class NativeWindowFactory {
public static ToolkitLock getNullToolkitLock() {
return NativeWindowFactoryImpl.getNullToolkitLock();
}
-
- public static ToolkitLock getGlobalToolkitLock() {
- return NativeWindowFactoryImpl.getGlobalToolkitLock();
- }
/**
+ * Ony call this for small code segments for desktop w/ threading issues.
+ * @return {@link GlobalToolkitLock} if desktop has threading issues, otherwise {@link #getNullToolkitLock()}
+ */
+ public static ToolkitLock getGlobalToolkitLockIfRequired() {
+ return desktopHasThreadingIssues ? GlobalToolkitLock.getSingleton() : getNullToolkitLock();
+ }
+
+ /**
* Provides the system default {@link ToolkitLock} for the default system windowing type.
* @see #getNativeWindowType(boolean)
* @see #getDefaultToolkitLock(java.lang.String)
@@ -400,7 +396,6 @@ public abstract class NativeWindowFactory {
* Provides the default {@link ToolkitLock} for <code>type</code>.
* <ul>
* <li> JAWT {@link ToolkitLock} if required and <code>type</code> is of {@link #TYPE_AWT} and AWT available,</li>
- * <li> {@link jogamp.nativewindow.GlobalToolkitLock} if required, otherwise</li>
* <li> {@link jogamp.nativewindow.ResourceToolkitLock} if required, otherwise</li>
* <li> {@link jogamp.nativewindow.NullToolkitLock} </li>
* </ul>
@@ -410,9 +405,6 @@ public abstract class NativeWindowFactory {
if( TYPE_AWT == type && isAWTAvailable() ) {
return getAWTToolkitLock();
}
- if( requiresGlobalToolkitLock ) {
- return NativeWindowFactoryImpl.getGlobalToolkitLock();
- }
return ResourceToolkitLock.create();
}
return NativeWindowFactoryImpl.getNullToolkitLock();
@@ -422,7 +414,6 @@ public abstract class NativeWindowFactory {
* Provides the default {@link ToolkitLock} for <code>type</code> and <code>deviceHandle</code>.
* <ul>
* <li> JAWT {@link ToolkitLock} if required and <code>type</code> is of {@link #TYPE_AWT} and AWT available,</li>
- * <li> {@link jogamp.nativewindow.GlobalToolkitLock} if required, otherwise</li>
* <li> {@link jogamp.nativewindow.ResourceToolkitLock} if required, otherwise</li>
* <li> {@link jogamp.nativewindow.NullToolkitLock} </li>
* </ul>
@@ -432,9 +423,6 @@ public abstract class NativeWindowFactory {
if( TYPE_AWT == type && isAWTAvailable() ) {
return getAWTToolkitLock();
}
- if( requiresGlobalToolkitLock ) {
- return NativeWindowFactoryImpl.getGlobalToolkitLock();
- }
return ResourceToolkitLock.create();
}
return NativeWindowFactoryImpl.getNullToolkitLock();
diff --git a/src/nativewindow/classes/jogamp/nativewindow/GlobalToolkitLock.java b/src/nativewindow/classes/jogamp/nativewindow/GlobalToolkitLock.java
index 0c2a1e43f..c9f830811 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/GlobalToolkitLock.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/GlobalToolkitLock.java
@@ -36,16 +36,19 @@ import com.jogamp.common.util.locks.RecursiveLock;
/**
* Implementing a global recursive {@link javax.media.nativewindow.ToolkitLock}.
* <p>
- * This is the last resort for unstable driver, e.g. proprietary ATI/X11 12.8 and 12.9,
- * where multiple X11 display connections to the same connection name are not treated
- * thread safe within the GL/X11 driver.
+ * This is the last resort for unstable driver where multiple X11 display connections
+ * to the same connection name are not treated thread safe within the GL/X11 driver.
* </p>
*/
public class GlobalToolkitLock implements ToolkitLock {
private static final RecursiveLock globalLock = LockFactory.createRecursiveLock();
+ private static GlobalToolkitLock singleton = new GlobalToolkitLock();
- /** Singleton via {@link NativeWindowFactoryImpl#getGlobalToolkitLock()} */
- protected GlobalToolkitLock() { }
+ public static final GlobalToolkitLock getSingleton() {
+ return singleton;
+ }
+
+ private GlobalToolkitLock() { }
@Override
public final void lock() {
diff --git a/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java b/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java
index c35cede77..a3a66b7f1 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java
@@ -44,16 +44,11 @@ import com.jogamp.common.util.ReflectionUtil.AWTNames;
public class NativeWindowFactoryImpl extends NativeWindowFactory {
private static final ToolkitLock nullToolkitLock = new NullToolkitLock();
- private static final ToolkitLock globalToolkitLock = new GlobalToolkitLock();
public static ToolkitLock getNullToolkitLock() {
return nullToolkitLock;
}
- public static ToolkitLock getGlobalToolkitLock() {
- return globalToolkitLock;
- }
-
// This subclass of NativeWindowFactory handles the case of
// NativeWindows being passed in
protected NativeWindow getNativeWindowImpl(Object winObj, AbstractGraphicsConfiguration config) throws IllegalArgumentException {
diff --git a/src/nativewindow/classes/jogamp/nativewindow/ToolkitProperties.java b/src/nativewindow/classes/jogamp/nativewindow/ToolkitProperties.java
index 2062d1f58..ed23def8f 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/ToolkitProperties.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/ToolkitProperties.java
@@ -13,15 +13,11 @@ import javax.media.nativewindow.NativeWindowFactory;
public static boolean requiresToolkitLock() {}
- public static boolean requiresGlobalToolkitLock() {}
+ public static boolean hasThreadingIssues() {}
* </pre>
* Above static methods are invoked by {@link NativeWindowFactory#initSingleton()},
* or {@link NativeWindowFactory#shutdown()} via reflection.
* </p>
- * <p>
- * If <code>requiresGlobalToolkitLock() == true</code>, then
- * <code>requiresToolkitLock() == true</code> shall be valid as well.
- * </p>
*/
public interface ToolkitProperties {
@@ -46,6 +42,6 @@ public interface ToolkitProperties {
/**
* Called by {@link NativeWindowFactory#initSingleton()}
*/
- // boolean requiresGlobalToolkitLock();
+ // boolean hasThreadingIssues();
}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
index 67c64a95c..349da8ee6 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
@@ -237,18 +237,15 @@ public class JAWTUtil {
jawtToolkitLock = new ToolkitLock() {
public final void lock() {
- NativeWindowFactory.getGlobalToolkitLock().lock();
JAWTUtil.lockToolkit();
if(TRACE_LOCK) { System.err.println("JAWTToolkitLock.lock()"); }
}
public final void unlock() {
if(TRACE_LOCK) { System.err.println("JAWTToolkitLock.unlock()"); }
JAWTUtil.unlockToolkit();
- NativeWindowFactory.getGlobalToolkitLock().unlock();
}
@Override
public final void validateLocked() throws RuntimeException {
- NativeWindowFactory.getGlobalToolkitLock().validateLocked();
JAWTUtil.validateLocked();
}
public final void dispose() {
diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
index 481cbbe39..a195f137e 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
@@ -76,7 +76,7 @@ public class OSXUtil implements ToolkitProperties {
* Called by {@link NativeWindowFactory#initSingleton()}
* @see ToolkitProperties
*/
- public static final boolean requiresGlobalToolkitLock() { return false; }
+ public static final boolean hasThreadingIssues() { return false; }
public static boolean isNSView(long object) {
return isNSView0(object);
diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java b/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java
index 4408a0903..2f4e18359 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java
@@ -84,7 +84,7 @@ public class GDIUtil implements ToolkitProperties {
* Called by {@link NativeWindowFactory#initSingleton()}
* @see ToolkitProperties
*/
- public static final boolean requiresGlobalToolkitLock() { return false; }
+ public static final boolean hasThreadingIssues() { return false; }
private static RegisteredClass dummyWindowClass = null;
private static Object dummyWindowSync = new Object();
diff --git a/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java b/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java
index 103995a8d..c771cd67a 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java
@@ -95,7 +95,7 @@ public class X11Util implements ToolkitProperties {
private static String nullDisplayName = null;
private static volatile boolean isInit = false;
private static boolean markAllDisplaysUnclosable = false; // ATI/AMD X11 driver issues
- private static boolean requiresGlobalToolkitLock = false; // ATI/AMD X11 driver issues
+ private static boolean hasThreadingIssues = false; // ATI/AMD X11 driver issues
private static Object setX11ErrorHandlerLock = new Object();
private static final String X11_EXTENSION_ATIFGLRXDRI = "ATIFGLRXDRI";
@@ -137,7 +137,7 @@ public class X11Util implements ToolkitProperties {
hasX11_EXTENSION_ATIFGLRXDRI = false;
hasX11_EXTENSION_ATIFGLEXTENSION = false;
}
- requiresGlobalToolkitLock = ATI_HAS_MULTITHREADING_BUG && ( hasX11_EXTENSION_ATIFGLRXDRI || hasX11_EXTENSION_ATIFGLEXTENSION );
+ hasThreadingIssues = ATI_HAS_MULTITHREADING_BUG && ( hasX11_EXTENSION_ATIFGLRXDRI || hasX11_EXTENSION_ATIFGLEXTENSION );
markAllDisplaysUnclosable = ATI_HAS_XCLOSEDISPLAY_BUG && ( hasX11_EXTENSION_ATIFGLRXDRI || hasX11_EXTENSION_ATIFGLEXTENSION );
if(DEBUG) {
@@ -147,7 +147,7 @@ public class X11Util implements ToolkitProperties {
",\n\t X11_EXTENSION_ATIFGLRXDRI " + hasX11_EXTENSION_ATIFGLRXDRI+
",\n\t X11_EXTENSION_ATIFGLEXTENSION " + hasX11_EXTENSION_ATIFGLEXTENSION+
",\n\t requiresToolkitLock "+requiresToolkitLock()+
- ",\n\t requiresGlobalToolkitLock "+requiresGlobalToolkitLock()+
+ ",\n\t hasThreadingIssues "+hasThreadingIssues()+
",\n\t markAllDisplaysUnclosable "+getMarkAllDisplaysUnclosable()
);
// Thread.dumpStack();
@@ -228,8 +228,8 @@ public class X11Util implements ToolkitProperties {
* Called by {@link NativeWindowFactory#initSingleton()}
* @see ToolkitProperties
*/
- public static final boolean requiresGlobalToolkitLock() {
- return requiresGlobalToolkitLock; // JAWT locking: yes, instead of native X11 locking w use a global lock.
+ public static final boolean hasThreadingIssues() {
+ return hasThreadingIssues; // JOGL impl. may utilize special locking "somewhere"
}
public static void setX11ErrorHandler(boolean onoff, boolean quiet) {
diff --git a/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java
index 6e80e966a..a3230fa62 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java
@@ -80,7 +80,7 @@ public class DisplayDriver extends DisplayImpl {
if( 0 == handle ) {
throw new RuntimeException("Error creating display(Win): "+name);
}
- aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, true);
+ aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, true /* owner */);
try {
CompleteDisplay0(aDevice.getHandle());
} catch(RuntimeException e) {
diff --git a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
index bde723634..92f174e39 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
@@ -73,7 +73,7 @@ public class WindowDriver extends WindowImpl {
if( 0 == renderDeviceHandle ) {
throw new RuntimeException("Error creating display(EDT): "+edtDevice.getConnection());
}
- renderDevice = new X11GraphicsDevice(renderDeviceHandle, AbstractGraphicsDevice.DEFAULT_UNIT, true);
+ renderDevice = new X11GraphicsDevice(renderDeviceHandle, AbstractGraphicsDevice.DEFAULT_UNIT, true /* owner */);
final AbstractGraphicsScreen renderScreen = new X11GraphicsScreen(renderDevice, screen.getIndex());
final GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice(), capsRequested);
diff --git a/src/newt/native/X11Display.c b/src/newt/native/X11Display.c
index 56c11fab4..69a115ab1 100644
--- a/src/newt/native/X11Display.c
+++ b/src/newt/native/X11Display.c
@@ -329,10 +329,10 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessage
char text[255];
// XEventsQueued(dpy, X):
- // QueuedAlready : No I/O Flush or system call doesn't work on some cards (eg ATI) ?)
+ // QueuedAlready == XQLength(): No I/O Flush or system call doesn't work on some cards (eg ATI) ?)
// QueuedAfterFlush == XPending(): I/O Flush only if no already queued events are available
// QueuedAfterReading : QueuedAlready + if queue==0, attempt to read more ..
- if ( 0 >= XPending(dpy) ) {
+ if ( 0 >= XEventsQueued(dpy, QueuedAfterFlush) ) {
// DBG_PRINT( "X11: DispatchMessages 0x%X - Leave 1\n", dpy);
return;
}
diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c
index 2e16e7cae..202ad6fff 100644
--- a/src/newt/native/X11Window.c
+++ b/src/newt/native/X11Window.c
@@ -701,7 +701,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_WindowDriver_CloseWindow0
Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessages0(env, obj, display, javaObjectAtom, windowDeleteAtom);
XDestroyWindow(dpy, w);
- XSync(dpy, False);
+ XSync(dpy, True); // discard all events now, no more handler
(*env)->DeleteGlobalRef(env, jwindow);