changeset 5721:eaa5e32c9952

RT-32436: Gtk: OpenGL with JavaFX causes Gthread error and halts Reviewed-by: anthony
author azvegint <alexander.zvegintsev@oracle.com>
date Fri, 15 Nov 2013 14:10:20 +0400
parents 68424b0eb120
children 8bbfe55df11c
files build.properties modules/graphics/src/main/native-glass/gtk/glass_general.cpp
diffstat 2 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/build.properties	Fri Nov 15 00:06:21 2013 -0800
+++ b/build.properties	Fri Nov 15 14:10:20 2013 +0400
@@ -63,4 +63,4 @@
 
 jfx.build.jdk.version=1.8.0
 jfx.build.jdk.buildnum=115
-jfx.build.jdk.buildnum.min=113
+jfx.build.jdk.buildnum.min=115
--- a/modules/graphics/src/main/native-glass/gtk/glass_general.cpp	Fri Nov 15 00:06:21 2013 -0800
+++ b/modules/graphics/src/main/native-glass/gtk/glass_general.cpp	Fri Nov 15 14:10:20 2013 +0400
@@ -107,6 +107,13 @@
 jfieldID jApplicationVisualID;
 jmethodID jApplicationReportException;
 
+void init_threads() {
+    if (!g_thread_supported()) {
+        g_thread_init(NULL);
+    }
+    gdk_threads_init();
+}
+
 JNIEXPORT jint JNICALL
 JNI_OnLoad(JavaVM *jvm, void *reserved)
 {
@@ -212,8 +219,24 @@
     jApplicationReportException = env->GetStaticMethodID(
         jApplicationCls, "reportException", "(Ljava/lang/Throwable;)V");
 
-    g_thread_init(NULL);
-    gdk_threads_init();
+    clazz = env->FindClass("sun/misc/GThreadHelper");
+    if (clazz) {
+        jmethodID mid_getAndSetInitializationNeededFlag = env->GetStaticMethodID(clazz, "getAndSetInitializationNeededFlag", "()Z");
+        jmethodID mid_lock = env->GetStaticMethodID(clazz, "lock", "()V");
+        jmethodID mid_unlock = env->GetStaticMethodID(clazz, "unlock", "()V");
+
+        env->CallStaticVoidMethod(clazz, mid_lock);
+
+        if (!env->CallStaticBooleanMethod(clazz, mid_getAndSetInitializationNeededFlag)) {
+            init_threads();
+        }
+
+        env->CallStaticVoidMethod(clazz, mid_unlock);
+    } else {
+        env->ExceptionClear();
+        init_threads();
+    }
+
     gdk_threads_enter();
     gtk_init(NULL, NULL);