aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-11-03 07:14:55 +0100
committerSven Gothel <[email protected]>2010-11-03 07:14:55 +0100
commit2b24c35472c0cb570674833ea1626df47fb0d721 (patch)
tree8170c476c3568cb9b163ec848af7bdf3d30518ef
parentaf3de7dd59bcebde68f3928868b5dde198978854 (diff)
NativeWindow: Provide 'setX11ErrorHandler(boolean onoff)'
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java31
-rw-r--r--src/nativewindow/native/x11/Xmisc.c32
2 files changed, 51 insertions, 12 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java
index 524b142ec..c449d8f86 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java
@@ -33,8 +33,6 @@
package com.jogamp.nativewindow.impl.x11;
-import java.util.HashMap;
-import java.util.Map;
import com.jogamp.common.util.LongObjectHashMap;
import javax.media.nativewindow.*;
@@ -58,6 +56,9 @@ public class X11Util {
private static boolean isFirstX11ActionOnProcess = false;
private static boolean isInit = false;
+ private static int setX11ErrorHandlerRecCount = 0;
+ private static Object setX11ErrorHandlerLock = new Object();
+
public static synchronized void initSingleton(boolean firstX11ActionOnProcess) {
if(!isInit) {
NWJNILibLoader.loadNativeWindow("x11");
@@ -65,8 +66,8 @@ public class X11Util {
/**
* Always issue XInitThreads() since we have independent
* off-thread created Display connections able to utilize multithreading, ie NEWT */
- initialize( true );
- // initialize( firstX11ActionOnProcess );
+ initialize0( true );
+ // initialize0( firstX11ActionOnProcess );
isFirstX11ActionOnProcess = firstX11ActionOnProcess;
if(DEBUG) {
@@ -76,6 +77,25 @@ public class X11Util {
}
}
+ public static void setX11ErrorHandler(boolean onoff) {
+ synchronized(setX11ErrorHandlerLock) {
+ if(onoff) {
+ if(0==setX11ErrorHandlerRecCount) {
+ setX11ErrorHandler0(true);
+ }
+ setX11ErrorHandlerRecCount++;
+ } else {
+ if(0 >= setX11ErrorHandlerRecCount) {
+ throw new InternalError();
+ }
+ setX11ErrorHandlerRecCount--;
+ if(0==setX11ErrorHandlerRecCount) {
+ setX11ErrorHandler0(false);
+ }
+ }
+ }
+ }
+
public static boolean isFirstX11ActionOnProcess() {
return isFirstX11ActionOnProcess;
}
@@ -574,5 +594,6 @@ public class X11Util {
X11Lib.XUnlockDisplay(handle);
}
- private static native void initialize(boolean firstUIActionOnProcess);
+ private static native void initialize0(boolean firstUIActionOnProcess);
+ private static native void setX11ErrorHandler0(boolean onoff);
}
diff --git a/src/nativewindow/native/x11/Xmisc.c b/src/nativewindow/native/x11/Xmisc.c
index 5a17bdb8f..831d94636 100644
--- a/src/nativewindow/native/x11/Xmisc.c
+++ b/src/nativewindow/native/x11/Xmisc.c
@@ -181,20 +181,25 @@ static void _throwNewRuntimeException(Display * unlockDisplay, JNIEnv *env, cons
static JNIEnv * x11ErrorHandlerJNIEnv = NULL;
static XErrorHandler origErrorHandler = NULL ;
+static int errorHandlerBlocked = 0 ;
static int x11ErrorHandler(Display *dpy, XErrorEvent *e)
{
- fprintf(stderr, "Nativewindow X11 Error: Display %p, Code 0x%X, errno %s\n", dpy, e->error_code, strerror(errno));
- _throwNewRuntimeException(NULL, x11ErrorHandlerJNIEnv, "Nativewindow X11 Error: Display %p, Code 0x%X, errno %s",
+ _throwNewRuntimeException(NULL, x11ErrorHandlerJNIEnv, "Info: Nativewindow X11 Error: Display %p, Code 0x%X, errno %s",
dpy, e->error_code, strerror(errno));
+
+#if 0
if(NULL!=origErrorHandler) {
origErrorHandler(dpy, e);
}
+#endif
return 0;
}
static void x11ErrorHandlerEnable(Display *dpy, int onoff, JNIEnv * env) {
+ if(errorHandlerBlocked) return;
+
if(onoff) {
if(NULL==origErrorHandler) {
x11ErrorHandlerJNIEnv = env;
@@ -204,14 +209,22 @@ static void x11ErrorHandlerEnable(Display *dpy, int onoff, JNIEnv * env) {
origErrorHandler = XSetErrorHandler(x11ErrorHandler);
}
} else {
- if(NULL!=dpy) {
- XSync(dpy, False);
+ if(NULL!=origErrorHandler) {
+ if(NULL!=dpy) {
+ XSync(dpy, False);
+ }
+ XSetErrorHandler(origErrorHandler);
+ origErrorHandler = NULL;
}
- XSetErrorHandler(origErrorHandler);
- origErrorHandler = NULL;
}
}
+static void x11ErrorHandlerEnableBlocking(int onoff, JNIEnv * env) {
+ errorHandlerBlocked = 0 ;
+ x11ErrorHandlerEnable(NULL, onoff, env);
+ errorHandlerBlocked = onoff ;
+}
+
static XIOErrorHandler origIOErrorHandler = NULL;
@@ -240,7 +253,7 @@ static void x11IOErrorHandlerEnable(int onoff, JNIEnv * env) {
static int _initialized=0;
JNIEXPORT void JNICALL
-Java_com_jogamp_nativewindow_impl_x11_X11Util_initialize(JNIEnv *env, jclass _unused, jboolean firstUIActionOnProcess) {
+Java_com_jogamp_nativewindow_impl_x11_X11Util_initialize0(JNIEnv *env, jclass _unused, jboolean firstUIActionOnProcess) {
if(0==_initialized) {
if( JNI_TRUE == firstUIActionOnProcess ) {
if( 0 == XInitThreads() ) {
@@ -258,6 +271,11 @@ Java_com_jogamp_nativewindow_impl_x11_X11Util_initialize(JNIEnv *env, jclass _un
}
}
+JNIEXPORT void JNICALL
+Java_com_jogamp_nativewindow_impl_x11_X11Util_setX11ErrorHandler0(JNIEnv *env, jclass _unused, jboolean onoff) {
+ x11ErrorHandlerEnableBlocking(( JNI_TRUE == onoff ) ? 1 : 0, env);
+}
+
/* Java->C glue code:
* Java package: com.jogamp.nativewindow.impl.x11.X11Lib
* Java method: XVisualInfo XGetVisualInfo(long arg0, long arg1, XVisualInfo arg2, java.nio.IntBuffer arg3)