changeset 3808:eaf163a8953c

RT-30557 Gtk: Unable to showAndWait a Stage from within an UncaughtExceptionHandler in Linux
author Alexander Zvegintsev
date Tue, 04 Jun 2013 14:13:51 +0400
parents 1dd4bb7090a2
children 61ec5d95c144
files glass/glass-lib-gtk/src/GlassApplication.cpp glass/glass-lib-gtk/src/GlassCommonDialogs.cpp glass/glass-lib-gtk/src/GlassCursor.cpp glass/glass-lib-gtk/src/GlassSystemClipboard.cpp glass/glass-lib-gtk/src/GlassTimer.cpp glass/glass-lib-gtk/src/GlassView.cpp glass/glass-lib-gtk/src/GlassWindow.cpp glass/glass-lib-gtk/src/glass_dnd.cpp glass/glass-lib-gtk/src/glass_general.cpp glass/glass-lib-gtk/src/glass_general.h glass/glass-lib-gtk/src/glass_window.cpp glass/glass-lib-gtk/src/glass_window.h glass/glass-lib-gtk/src/glass_window_ime.cpp
diffstat 13 files changed, 107 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/glass/glass-lib-gtk/src/GlassApplication.cpp	Tue Jun 04 14:05:54 2013 +0400
+++ b/glass/glass-lib-gtk/src/GlassApplication.cpp	Tue Jun 04 14:13:51 2013 +0400
@@ -57,7 +57,6 @@
 
     mainEnv->CallVoidMethod(context->runnable, jRunnableRun, NULL);
     LOG_EXCEPTION(mainEnv);
-    mainEnv->ExceptionClear();
     mainEnv->DeleteGlobalRef(context->runnable);
     free(context);
     return FALSE;
@@ -188,7 +187,6 @@
 static void screen_settings_changed(GdkScreen* screen, gpointer user_data) {
     mainEnv->CallStaticVoidMethod(jScreenCls, jScreenNotifySettingsChanged);
     LOG_EXCEPTION(mainEnv);
-    mainEnv->ExceptionClear(); //This is callback, so clear
 }
 
 extern "C" {
@@ -530,8 +528,6 @@
                     break;
             }
         } catch (jni_exception&) {
-            LOG_EXCEPTION(mainEnv);
-            mainEnv->ExceptionClear();
         }
     } else {
 
--- a/glass/glass-lib-gtk/src/GlassCommonDialogs.cpp	Tue Jun 04 14:05:54 2013 +0400
+++ b/glass/glass-lib-gtk/src/GlassCommonDialogs.cpp	Tue Jun 04 14:13:51 2013 +0400
@@ -153,6 +153,7 @@
     
     jobject result =
             env->CallStaticObjectMethod(jCommonDialogs, jCreateFileChooserResult, jFileNames, jFilters, index);
+    LOG_EXCEPTION(env)
     
     g_slist_free(filters);
     gtk_widget_destroy(chooser);
--- a/glass/glass-lib-gtk/src/GlassCursor.cpp	Tue Jun 04 14:05:54 2013 +0400
+++ b/glass/glass-lib-gtk/src/GlassCursor.cpp	Tue Jun 04 14:13:51 2013 +0400
@@ -181,10 +181,12 @@
 JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_gtk_GtkCursor__1createCursor
   (JNIEnv * env, jobject obj, jint x, jint y, jobject pixels)
 {
-    GdkPixbuf *pixbuf;
+    GdkPixbuf *pixbuf = NULL;
+    GdkCursor *cursor = NULL;
     env->CallVoidMethod(pixels, jPixelsAttachData, PTR_TO_JLONG(&pixbuf));
-    
-    GdkCursor *cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, x, y);
+    if (!EXCEPTION_OCCURED(env)) {
+        cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, x, y);
+    }
     g_object_unref(pixbuf);
 
     return PTR_TO_JLONG(cursor);
--- a/glass/glass-lib-gtk/src/GlassSystemClipboard.cpp	Tue Jun 04 14:05:54 2013 +0400
+++ b/glass/glass-lib-gtk/src/GlassSystemClipboard.cpp	Tue Jun 04 14:13:51 2013 +0400
@@ -128,6 +128,7 @@
 static void set_bytebuffer_data(GtkSelectionData *selection_data, GdkAtom target, jobject data)
 {
     jbyteArray byteArray = (jbyteArray) mainEnv->CallObjectMethod(data, jByteBufferArray);
+    CHECK_JNI_EXCEPTION(mainEnv)
     jbyte* raw = mainEnv->GetByteArrayElements(byteArray, NULL);
     jsize nraw = mainEnv->GetArrayLength(byteArray);
 
@@ -182,11 +183,12 @@
 
 static void set_image_data(GtkSelectionData *selection_data, jobject pixels)
 {
-    GdkPixbuf *pixbuf;
+    GdkPixbuf *pixbuf = NULL;
 
     mainEnv->CallVoidMethod(pixels, jPixelsAttachData, PTR_TO_JLONG(&pixbuf));
-    CHECK_JNI_EXCEPTION(mainEnv);
-    gtk_selection_data_set_pixbuf(selection_data, pixbuf);
+    if (!EXCEPTION_OCCURED(mainEnv)) {
+        gtk_selection_data_set_pixbuf(selection_data, pixbuf);
+    }
 
     g_object_unref(pixbuf);
 }
@@ -200,31 +202,33 @@
     if (gtk_targets_include_text(&target, 1)) {
         typeString = mainEnv->NewStringUTF("text/plain");
         result = mainEnv->CallObjectMethod(data, jMapGet, typeString, NULL);
-        if (result != NULL)
+        if (!EXCEPTION_OCCURED(mainEnv) && result != NULL) {
             set_text_data(selection_data, (jstring)result);
+        }
     } else if (gtk_targets_include_image(&target, 1, TRUE)) {
         typeString = mainEnv->NewStringUTF("application/x-java-rawimage");
         result = mainEnv->CallObjectMethod(data, jMapGet, typeString, NULL);
-        if (result != NULL) {
+        if (!EXCEPTION_OCCURED(mainEnv) && result != NULL) {
             set_image_data(selection_data, result);
-            CHECK_JNI_EXCEPTION(mainEnv);
         }
     } else if (target == MIME_TEXT_URI_LIST_TARGET) {
         typeString = mainEnv->NewStringUTF(name);
         if (mainEnv->CallBooleanMethod(data, jMapContainsKey, typeString, NULL)) {
             result = mainEnv->CallObjectMethod(data, jMapGet, typeString, NULL);
-            if (result != NULL)
+            if (!EXCEPTION_OCCURED(mainEnv) && result != NULL) {
                 set_jstring_data(selection_data, target, (jstring)result);
+            }
         } else {
             typeString = mainEnv->NewStringUTF("application/x-java-file-list");
             result = mainEnv->CallObjectMethod(data, jMapGet, typeString, NULL);
-            if (result != NULL)
+            if (!EXCEPTION_OCCURED(mainEnv) && result != NULL) {
                 set_file_uri_data(selection_data, (jobjectArray) result);
+            }
         }
     } else {
         typeString = mainEnv->NewStringUTF(name);
         result = mainEnv->CallObjectMethod(data, jMapGet, typeString, NULL);
-        if (result != NULL) {
+        if (!EXCEPTION_OCCURED(mainEnv) && result != NULL) {
             if (mainEnv->IsInstanceOf(result, jStringCls)) {
                 set_jstring_data(selection_data, target, (jstring)result);
             } else if (mainEnv->IsInstanceOf(result, jByteBufferCls)) {
@@ -244,8 +248,7 @@
     target = gtk_selection_data_get_target(selection_data);
 
     set_data(target, selection_data, data);
-    LOG_EXCEPTION(mainEnv);
-    mainEnv->ExceptionClear();
+    CHECK_JNI_EXCEPTION(mainEnv);
 }
 
 static void clear_data_func(GtkClipboard *clipboard, gpointer user_data)
@@ -360,6 +363,7 @@
 static void clipboard_owner_changed_callback(GtkClipboard *clipboard, GdkEventOwnerChange *event, jobject obj)
 {
     mainEnv->CallVoidMethod(obj, jClipboardContentChanged);
+    CHECK_JNI_EXCEPTION(mainEnv)
 }
 
 extern "C" {
@@ -470,7 +474,7 @@
     } else {
         result = get_data_raw(env, cmime, FALSE);
     }
-
+    LOG_EXCEPTION(env)
     env->ReleaseStringUTFChars(mime, cmime);
 
     return result;
@@ -511,7 +515,7 @@
 
     convertible = (GdkAtom*) glass_try_malloc_n(ntargets * 2, sizeof(GdkAtom)); //theoretically, the number can double
     if (!convertible) {
-        if (ntargets) {
+        if (ntargets > 0) {
             glass_throw_oom(env, "Failed to allocate mimes");
         }
         g_free(targets);
--- a/glass/glass-lib-gtk/src/GlassTimer.cpp	Tue Jun 04 14:05:54 2013 +0400
+++ b/glass/glass-lib-gtk/src/GlassTimer.cpp	Tue Jun 04 14:13:51 2013 +0400
@@ -77,7 +77,6 @@
     else if (context->runnable) {
         mainEnv->CallVoidMethod(context->runnable, jRunnableRun, NULL);
         LOG_EXCEPTION(mainEnv);
-        mainEnv->ExceptionClear();
     }
     return TRUE;
 }
--- a/glass/glass-lib-gtk/src/GlassView.cpp	Tue Jun 04 14:05:54 2013 +0400
+++ b/glass/glass-lib-gtk/src/GlassView.cpp	Tue Jun 04 14:13:51 2013 +0400
@@ -240,6 +240,7 @@
     if (view->current_window) {
         view->current_window->enter_fullscreen();
         env->CallVoidMethod(obj, jViewNotifyView, com_sun_glass_events_ViewEvent_FULLSCREEN_ENTER);
+        CHECK_JNI_EXCEPTION_RET(env, JNI_FALSE)
     }
     return JNI_TRUE;
 }
@@ -260,6 +261,7 @@
             view->current_window->exit_fullscreen();
         }
         env->CallVoidMethod(obj, jViewNotifyView, com_sun_glass_events_ViewEvent_FULLSCREEN_EXIT);
+        CHECK_JNI_EXCEPTION(env)
     }
 
 }
--- a/glass/glass-lib-gtk/src/GlassWindow.cpp	Tue Jun 04 14:05:54 2013 +0400
+++ b/glass/glass-lib-gtk/src/GlassWindow.cpp	Tue Jun 04 14:13:51 2013 +0400
@@ -136,12 +136,7 @@
   (JNIEnv * env, jobject obj, jlong ptr, jobject view)
 {
     WindowContext* ctx = JLONG_TO_WINDOW_CTX(ptr);
-    try {
-        ctx->set_view(view);
-    } catch (jni_exception&) {
-        return JNI_FALSE;
-    }
-    return JNI_TRUE;
+    return (ctx->set_view(view)) ? JNI_TRUE : JNI_FALSE;
 }
 /*
  * Class:     com_sun_glass_ui_gtk_GtkWindow
@@ -370,11 +365,11 @@
   (JNIEnv * env, jobject obj, jlong ptr, jobject pixels)
 {
     WindowContext* ctx = JLONG_TO_WINDOW_CTX(ptr);
-    GdkPixbuf *pixbuf;
+    GdkPixbuf *pixbuf = NULL;
     env->CallVoidMethod(pixels, jPixelsAttachData, PTR_TO_JLONG(&pixbuf));
-    CHECK_JNI_EXCEPTION(env)
-
-    ctx->set_icon(pixbuf);
+    if (!EXCEPTION_OCCURED(env)) {
+        ctx->set_icon(pixbuf);
+    }
     g_object_unref(pixbuf);
 }
 
--- a/glass/glass-lib-gtk/src/glass_dnd.cpp	Tue Jun 04 14:05:54 2013 +0400
+++ b/glass/glass-lib-gtk/src/glass_dnd.cpp	Tue Jun 04 14:13:51 2013 +0400
@@ -160,6 +160,7 @@
             (jint)event->x_root - enter_ctx.dx, (jint)event->y_root - enter_ctx.dy,
             (jint)event->x_root, (jint)event->y_root,
             translate_gdk_action_to_glass(suggested)));
+    CHECK_JNI_EXCEPTION(mainEnv)
     if (result != suggested && result != GDK_ACTION_COPY) {
         result = static_cast<GdkDragAction>(0);
     }
@@ -172,6 +173,7 @@
 static void process_dnd_target_drag_leave(WindowContext *ctx, GdkEventDND *event)
 {
     mainEnv->CallVoidMethod(ctx->get_jview(), jViewNotifyDragLeave, NULL);
+    CHECK_JNI_EXCEPTION(mainEnv)
 }
 
 static void process_dnd_target_drop_start(WindowContext *ctx, GdkEventDND *event)
@@ -187,6 +189,7 @@
             (jint)event->x_root - enter_ctx.dx, (jint)event->y_root - enter_ctx.dy,
             (jint)event->x_root, (jint)event->y_root,
             translate_gdk_action_to_glass(selected));
+    LOG_EXCEPTION(mainEnv)
 
     gdk_drop_finish(event->context, TRUE, GDK_CURRENT_TIME);
     gdk_drop_reply(event->context, TRUE, GDK_CURRENT_TIME);
@@ -466,7 +469,7 @@
     } else {
         ret = dnd_target_get_raw(env, gdk_atom_intern(cmime, FALSE), FALSE);
     }
-
+    LOG_EXCEPTION(env)
     env->ReleaseStringUTFChars(mime, cmime);
 
     return ret;
@@ -573,9 +576,9 @@
 {
     jobject data = (jobject)g_object_get_data(G_OBJECT(dnd_window), SOURCE_DND_DATA);
     jstring string = mainEnv->NewStringUTF(key);
-    
-    return mainEnv->CallObjectMethod(data, jMapGet, string, NULL);
-    
+    jobject result = mainEnv->CallObjectMethod(data, jMapGet, string, NULL);
+
+    return (EXCEPTION_OCCURED(mainEnv)) ? NULL : result;
 }
 
 static gboolean dnd_source_set_utf8_string(GdkWindow *requestor, GdkAtom property)
@@ -627,7 +630,8 @@
     gchar *buffer;
     gsize size;
     const char * type;
-    GdkPixbuf *pixbuf;
+    GdkPixbuf *pixbuf = NULL;
+    gboolean result = FALSE;
 
     if (target == TARGET_MIME_PNG_ATOM) {
         type = "png";
@@ -642,14 +646,15 @@
     }
 
     mainEnv->CallVoidMethod(pixels, jPixelsAttachData, PTR_TO_JLONG(&pixbuf));
-    
-    if (gdk_pixbuf_save_to_buffer(pixbuf, &buffer, &size, type, NULL, NULL)) {
+
+    if (!EXCEPTION_OCCURED(mainEnv)
+            && gdk_pixbuf_save_to_buffer(pixbuf, &buffer, &size, type, NULL, NULL)) {
         gdk_property_change(requestor, property, target,
                 8, GDK_PROP_MODE_REPLACE, (guchar *)buffer, size);
-    } else {
-        return FALSE;
+        result = TRUE;
     }
-    return TRUE;
+    g_object_unref(pixbuf);
+    return result;
 }
 
 #define FILE_PREFIX "file://"
@@ -727,14 +732,16 @@
             is_data_set = TRUE;
         } else if (mainEnv->IsInstanceOf(data, jByteBufferCls)) {
             jbyteArray byteArray = (jbyteArray)mainEnv->CallObjectMethod(data, jByteBufferArray);
-            jbyte* raw = mainEnv->GetByteArrayElements(byteArray, NULL);
-            jsize nraw = mainEnv->GetArrayLength(byteArray);
-    
-            gdk_property_change(requestor, property, target,
-                    8, GDK_PROP_MODE_REPLACE, (guchar *) raw, nraw);
-            
-            mainEnv->ReleaseByteArrayElements(byteArray, raw, JNI_ABORT);
-            is_data_set = TRUE;
+            if (!EXCEPTION_OCCURED(mainEnv)) {
+                jbyte* raw = mainEnv->GetByteArrayElements(byteArray, NULL);
+                jsize nraw = mainEnv->GetArrayLength(byteArray);
+
+                gdk_property_change(requestor, property, target,
+                        8, GDK_PROP_MODE_REPLACE, (guchar *) raw, nraw);
+
+                mainEnv->ReleaseByteArrayElements(byteArray, raw, JNI_ABORT);
+                is_data_set = TRUE;
+            }
         }
     }
     
--- a/glass/glass-lib-gtk/src/glass_general.cpp	Tue Jun 04 14:05:54 2013 +0400
+++ b/glass/glass-lib-gtk/src/glass_general.cpp	Tue Jun 04 14:13:51 2013 +0400
@@ -268,12 +268,14 @@
     }
 }
 
-void log_exception(JNIEnv *env) {
+gboolean check_and_clear_exception(JNIEnv *env) {
     jthrowable t = env->ExceptionOccurred();
     if (t) {
         env->ExceptionClear();
         env->CallStaticVoidMethod(jApplicationCls, jApplicationReportException, t);
+        return TRUE;
     }
+    return FALSE;
 }
 
 gpointer glass_try_malloc_n(gsize m, gsize n, 
--- a/glass/glass-lib-gtk/src/glass_general.h	Tue Jun 04 14:05:54 2013 +0400
+++ b/glass/glass-lib-gtk/src/glass_general.h	Tue Jun 04 14:13:51 2013 +0400
@@ -60,18 +60,23 @@
     jstring jmessage;
 };
 
+#define EXCEPTION_OCCURED(env) (check_and_clear_exception(env))
+
 #define CHECK_JNI_EXCEPTION(env) \
         if (env->ExceptionCheck()) {\
+            check_and_clear_exception(env);\
             return;\
         }
 
 #define CHECK_JNI_EXCEPTION_RET(env, ret) \
         if (env->ExceptionCheck()) {\
-                return ret;\
+            check_and_clear_exception(env);\
+            return ret;\
         }
 
 #define JNI_EXCEPTION_TO_CPP(env) \
         if (env->ExceptionCheck()) {\
+            check_and_clear_exception(env);\
             throw jni_exception(env->ExceptionOccurred());\
         }
 
@@ -204,7 +209,7 @@
 #define ERROR4(msg, param1, param2, param3, param4)
 #endif
 
-#define LOG_EXCEPTION(env) log_exception(env);
+#define LOG_EXCEPTION(env) check_and_clear_exception(env);
 
     void glass_throw_exception(JNIEnv * env,
             const char * exceptionClass,
@@ -214,7 +219,7 @@
 
     guint8* convert_BGRA_to_RGBA(const int* pixels, int stride, int height);
 
-    void log_exception(JNIEnv *env);
+    gboolean check_and_clear_exception(JNIEnv *env);
 
 #endif        /* GLASS_GENERAL_H */
 
--- a/glass/glass-lib-gtk/src/glass_window.cpp	Tue Jun 04 14:05:54 2013 +0400
+++ b/glass/glass-lib-gtk/src/glass_window.cpp	Tue Jun 04 14:13:51 2013 +0400
@@ -61,7 +61,9 @@
 
 bool WindowContextBase::isEnabled() {
     if (jwindow) {
-        return (JNI_TRUE == mainEnv->CallBooleanMethod(jwindow, jWindowIsEnabled));
+        bool result = (JNI_TRUE == mainEnv->CallBooleanMethod(jwindow, jWindowIsEnabled));
+        LOG_EXCEPTION(mainEnv)
+        return result;
     } else {
         return false;
     }
@@ -75,8 +77,10 @@
         if (!event->in || isEnabled()) {
             mainEnv->CallVoidMethod(jwindow, jWindowNotifyFocus,
                     event->in ? com_sun_glass_events_WindowEvent_FOCUS_GAINED : com_sun_glass_events_WindowEvent_FOCUS_LOST);
+            CHECK_JNI_EXCEPTION(mainEnv)
         } else {
             mainEnv->CallVoidMethod(jwindow, jWindowNotifyFocusDisabled);
+            CHECK_JNI_EXCEPTION(mainEnv)
         }
     }
 }
@@ -102,18 +106,21 @@
 
     if (jwindow) {
         mainEnv->CallVoidMethod(jwindow, jWindowNotifyDestroy);
+        CHECK_JNI_EXCEPTION(mainEnv)
     }
 }
 
 void WindowContextBase::process_delete() {
     if (jwindow && isEnabled()) {
         mainEnv->CallVoidMethod(jwindow, jWindowNotifyClose);
+        CHECK_JNI_EXCEPTION(mainEnv)
     }
 }
 
 void WindowContextBase::process_expose(GdkEventExpose* event) {
     if (jview) {
         mainEnv->CallVoidMethod(jview, jViewNotifyRepaint, event->area.x, event->area.y, event->area.width, event->area.height);
+        CHECK_JNI_EXCEPTION(mainEnv)
     }
 }
 
@@ -179,12 +186,14 @@
                 gdk_modifier_mask_to_glass(state),
                 (event->button == 3 && press) ? JNI_TRUE : JNI_FALSE,
                 JNI_FALSE);
+        CHECK_JNI_EXCEPTION(mainEnv)
 
-        if (event->button == 3 && press) {
+        if (jview && event->button == 3 && press) {
             mainEnv->CallVoidMethod(jview, jViewNotifyMenu,
                     (jint)event->x, (jint)event->y,
                     (jint)event->x_root, (jint)event->y_root,
                     JNI_FALSE);
+            CHECK_JNI_EXCEPTION(mainEnv)
         }
     }
 
@@ -215,6 +224,7 @@
                 glass_modifier,
                 JNI_FALSE,
                 JNI_FALSE);
+        CHECK_JNI_EXCEPTION(mainEnv)
     }
 }
 
@@ -247,6 +257,7 @@
                 (jint) 0, (jint) 0,
                 (jint) 0, (jint) 0,
                 (jdouble) 40.0, (jdouble) 40.0);
+        CHECK_JNI_EXCEPTION(mainEnv)
     }
 
 }
@@ -267,6 +278,7 @@
                 gdk_modifier_mask_to_glass(state),
                 JNI_FALSE,
                 JNI_FALSE);
+        CHECK_JNI_EXCEPTION(mainEnv)
     }
 }
 
@@ -396,7 +408,7 @@
     return gtk_widget_get_visible(gtk_widget);
 }
 
-void WindowContextBase::set_view(jobject view) {
+bool WindowContextBase::set_view(jobject view) {
 
     if (jview) {
         mainEnv->DeleteGlobalRef(jview);
@@ -407,10 +419,11 @@
         jview = mainEnv->NewGlobalRef(view);
         gtk_window_get_size(GTK_WINDOW(gtk_widget), &width, &height);
         mainEnv->CallVoidMethod(view, jViewNotifyResize, width, height);
+        CHECK_JNI_EXCEPTION_RET(mainEnv, FALSE)
     } else {
         jview = NULL;
     }
-
+    return TRUE;
 }
 
 bool WindowContextBase::grab_focus() {
@@ -428,6 +441,7 @@
 
     if (jwindow) {
         mainEnv->CallVoidMethod(jwindow, jWindowNotifyFocusUngrab);
+        CHECK_JNI_EXCEPTION(mainEnv)
     }
 }
 
@@ -715,6 +729,7 @@
 
             if (jview) {
                 mainEnv->CallVoidMethod(jview, jViewNotifyView, com_sun_glass_events_ViewEvent_MOVE);
+                CHECK_JNI_EXCEPTION(mainEnv)
             }
         }
     }
@@ -1233,20 +1248,19 @@
         mainEnv->CallVoidMethod(jview, jViewNotifyResize,
                 event->width,
                 event->height);
+        CHECK_JNI_EXCEPTION(mainEnv)
     }
 
     mainEnv->CallVoidMethod(jwindow, jWindowNotifyResize,
             com_sun_glass_events_WindowEvent_RESIZE,
             event->width,
             event->height);
+    CHECK_JNI_EXCEPTION(mainEnv)
 
     if (!embedded_children.empty()) {
         WindowContextChild* child = embedded_children.back();
         child->process_configure(event);
     }
-
-    mainEnv->ExceptionClear();
-
 }
 
 void WindowContextPlug::process_state(GdkEventWindowState *event) {
@@ -1267,8 +1281,8 @@
                 mainEnv->CallVoidMethod(jview,
                         jViewNotifyRepaint,
                         0, 0, w, h);
+                CHECK_JNI_EXCEPTION(mainEnv)
             }
-            CHECK_JNI_EXCEPTION(mainEnv);
         }
 
         mainEnv->CallVoidMethod(jwindow,
@@ -1278,7 +1292,7 @@
     }
 }
 
-void WindowContextPlug::set_view(jobject view) {
+bool WindowContextPlug::set_view(jobject view) {
     // probably never called for applet window
     if (jview) {
         mainEnv->DeleteGlobalRef(jview);
@@ -1289,9 +1303,11 @@
         jview = mainEnv->NewGlobalRef(view);
         gtk_window_get_size(GTK_WINDOW(gtk_widget), &width, &height);
         mainEnv->CallVoidMethod(view, jViewNotifyResize, width, height);
+        CHECK_JNI_EXCEPTION_RET(mainEnv, FALSE)
     } else {
         jview = NULL;
     }
+    return TRUE;
 }
 
 void WindowContextPlug::window_configure(XWindowChanges *windowChanges,
@@ -1429,6 +1445,7 @@
         mainEnv->CallVoidMethod(jview, jViewNotifyResize,
                 event->width,
                 event->height);
+        CHECK_JNI_EXCEPTION(mainEnv)
     }
 
     gtk_widget_set_size_request(gtk_widget, event->width, event->height);
@@ -1437,7 +1454,7 @@
             com_sun_glass_events_WindowEvent_RESIZE,
             event->width,
             event->height);
-
+    CHECK_JNI_EXCEPTION(mainEnv)
 }
 
 void WindowContextChild::process_state(GdkEventWindowState *event) {
@@ -1469,7 +1486,7 @@
     }
 }
 
-void WindowContextChild::set_view(jobject view) {
+bool WindowContextChild::set_view(jobject view) {
     if (jview) {
         mainEnv->DeleteGlobalRef(jview);
     }
@@ -1480,10 +1497,11 @@
         width = gtk_widget->allocation.width;
         height = gtk_widget->allocation.height;
         mainEnv->CallVoidMethod(view, jViewNotifyResize, width, height);
-        JNI_EXCEPTION_TO_CPP(mainEnv);
+        CHECK_JNI_EXCEPTION_RET(mainEnv, FALSE)
     } else {
         jview = NULL;
     }
+    return TRUE;
 }
 
 void WindowContextChild::set_bounds(int x, int y, bool xSet, bool ySet, int w, int h, int cw, int ch) {
@@ -1494,6 +1512,7 @@
         mainEnv->CallVoidMethod(jwindow,
                 jWindowNotifyMove,
                 newX, newY);
+        CHECK_JNI_EXCEPTION(mainEnv)
     }
 
     // As we have no frames, there's no difference between the calls
@@ -1518,6 +1537,7 @@
             mainEnv->CallVoidMethod(jview,
                     jViewNotifyResize,
                     newWidth, newHeight);
+            CHECK_JNI_EXCEPTION(mainEnv)
         }
     }
 }
@@ -1573,6 +1593,7 @@
     full_screen_window->enter_fullscreen();
 
     mainEnv->CallVoidMethod(jwindow, jWindowNotifyDelegatePtr, (jlong)full_screen_window);
+    CHECK_JNI_EXCEPTION(mainEnv)
 
     if (jview) {
         this->view = (GlassView*)mainEnv->GetLongField(jview, jViewPtr);
@@ -1596,6 +1617,7 @@
     full_screen_window->reparent_children(this);
 
     mainEnv->CallVoidMethod(jwindow, jWindowNotifyDelegatePtr, (jlong)NULL);
+    CHECK_JNI_EXCEPTION(mainEnv)
 
     if (this->view) {
         this->view->current_window = this;
--- a/glass/glass-lib-gtk/src/glass_window.h	Tue Jun 04 14:05:54 2013 +0400
+++ b/glass/glass-lib-gtk/src/glass_window.h	Tue Jun 04 14:13:51 2013 +0400
@@ -151,7 +151,7 @@
 
     virtual void add_child(WindowContextTop* child) = 0;
     virtual void remove_child(WindowContextTop* child) = 0;
-    virtual void set_view(jobject) = 0;
+    virtual bool set_view(jobject) = 0;
 
     virtual GdkWindow *get_gdk_window() = 0;
     virtual GtkWindow *get_gtk_window() = 0;
@@ -197,7 +197,7 @@
     void reparent_children(WindowContext* parent);
     void set_visible(bool);
     bool is_visible();
-    void set_view(jobject);
+    bool set_view(jobject);
     bool grab_focus();
     void ungrab_focus();
     void set_cursor(GdkCursor*);
@@ -228,7 +228,7 @@
 class WindowContextPlug: public WindowContextBase {
     WindowContext* parent;
 public:
-    void set_view(jobject);
+    bool set_view(jobject);
     void set_bounds(int, int, bool, bool, int, int, int, int);
     //WindowFrameExtents get_frame_extents() { return WindowFrameExtents{0, 0, 0, 0}; };
     WindowFrameExtents get_frame_extents() { WindowFrameExtents ext = {0, 0, 0, 0}; return ext;}
@@ -273,7 +273,7 @@
     GlassView* view; // not null while in Full Screen
 public:
     void process_mouse_button(GdkEventButton*);
-    void set_view(jobject);
+    bool set_view(jobject);
     void set_bounds(int, int, bool, bool, int, int, int, int);
     //WindowFrameExtents get_frame_extents() { return WindowFrameExtents{0, 0, 0, 0}; };
     WindowFrameExtents get_frame_extents() { WindowFrameExtents ext = {0, 0, 0, 0}; return ext;}
--- a/glass/glass-lib-gtk/src/glass_window_ime.cpp	Tue Jun 04 14:05:54 2013 +0400
+++ b/glass/glass-lib-gtk/src/glass_window_ime.cpp	Tue Jun 04 14:13:51 2013 +0400
@@ -97,6 +97,7 @@
                     slen,
                     slen,
                     0);
+            LOG_EXCEPTION(mainEnv)
 
             break;
     }
@@ -144,12 +145,14 @@
 
     mainEnv->CallVoidMethod((jobject)client, jViewNotifyInputMethodDraw,
             text, data->chg_first, data->chg_length, data->caret);
+    CHECK_JNI_EXCEPTION(mainEnv)
 }
 
 static void im_preedit_caret(XIM im_xim, XPointer client, XPointer call) {
     XIMPreeditCaretCallbackStruct *data = (XIMPreeditCaretCallbackStruct*) call;
     mainEnv->CallVoidMethod((jobject)client, jViewNotifyInputMethodCaret,
             data->position, data->direction, data->style);
+    CHECK_JNI_EXCEPTION(mainEnv)
 }
 
 static XIMStyle get_best_supported_style(XIM im_xim)