diff options
author | Sven Gothel <[email protected]> | 2011-04-26 07:41:17 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-04-26 07:41:17 +0200 |
commit | a9a52941ca052d6262dbad49acc0d3646730bae8 (patch) | |
tree | fea6caa4310bdd54016a1c43b08dbaff5f54de01 /src/newt | |
parent | 727ad54808664e3028fee64cfca98dd9f0bcfbf6 (diff) |
NEWT/X11 WindowClosing: End dispatch loop since Display could be destroyed after Java callback
Diffstat (limited to 'src/newt')
-rw-r--r-- | src/newt/native/X11Window.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index 66b036ef5..53dd97d44 100644 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -188,7 +188,18 @@ static jmethodID displayCompletedID = NULL; * Display */ -static JNIEnv * x11ErrorHandlerJNIEnv = NULL; +static JavaVM *jvmHandle = NULL; +static int jvmVersion = 0; +static JNIEnv * jvmEnv = NULL; + +static void setupJVMVars(JNIEnv * env) { + if(0 != (*env)->GetJavaVM(env, &jvmHandle)) { + jvmHandle = NULL; + } + jvmVersion = (*env)->GetVersion(env); + jvmEnv = env; +} + static XErrorHandler origErrorHandler = NULL ; static int displayDispatchErrorHandler(Display *dpy, XErrorEvent *e) @@ -200,7 +211,7 @@ static int displayDispatchErrorHandler(Display *dpy, XErrorEvent *e) } else if (e->error_code == BadWindow) { fprintf(stderr, " BadWindow (%p): Window probably already removed\n", (void*)e->resourceid); } else { - NewtCommon_throwNewRuntimeException(x11ErrorHandlerJNIEnv, "NEWT X11 Error: Display %p, Code 0x%X, errno %s", + NewtCommon_throwNewRuntimeException(jvmEnv, "NEWT X11 Error: Display %p, Code 0x%X, errno %s", dpy, e->error_code, strerror(errno)); } @@ -210,7 +221,7 @@ static int displayDispatchErrorHandler(Display *dpy, XErrorEvent *e) static void displayDispatchErrorHandlerEnable(int onoff, JNIEnv * env) { if(onoff) { if(NULL==origErrorHandler) { - x11ErrorHandlerJNIEnv = env; + setupJVMVars(env); origErrorHandler = XSetErrorHandler(displayDispatchErrorHandler); } } else { @@ -663,6 +674,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_x11_X11Display_DispatchMessages0 (void*)evt.xclient.window, (unsigned int)evt.xclient.message_type); (*env)->CallVoidMethod(env, jwindow, windowDestroyNotifyID); // Called by Window.java: CloseWindow(); + num_events = 0; // end loop in case of destroyed display } break; |