changeset 8014:926c9f860016

RT-38397: Mac: Application processes termination prematurely when a nested event loop is running Summary: Register the full screen exiting loop at Java level Reviewed-by: kcr, snorthov
author Anthony Petrov <anthony.petrov@oracle.com>
date Tue, 09 Sep 2014 17:41:46 +0400
parents d62cb8404b84
children 86b0f5599fad
files modules/graphics/src/main/native-glass/mac/GlassApplication.m modules/graphics/src/main/native-glass/mac/GlassStatics.h
diffstat 2 files changed, 14 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/native-glass/mac/GlassApplication.m	Tue Sep 09 11:01:12 2014 +0200
+++ b/modules/graphics/src/main/native-glass/mac/GlassApplication.m	Tue Sep 09 17:41:46 2014 +0400
@@ -678,7 +678,8 @@
 {
     isFullScreenExitingLoop = YES;
     GET_MAIN_JENV;
-    [GlassApplication enterNestedEventLoopWithEnv:env];
+    (*env)->CallStaticObjectMethod(env, jApplicationClass,
+            javaIDs.Application.enterNestedEventLoop);
     isFullScreenExitingLoop = NO;
 }
 
@@ -688,7 +689,8 @@
         return;
     }
     GET_MAIN_JENV;
-    [GlassApplication leaveNestedEventLoopWithEnv:env retValue:0L];
+    (*env)->CallStaticVoidMethod(env, jApplicationClass,
+            javaIDs.Application.leaveNestedEventLoop, (jobject)NULL);
 }
 
 + (void)registerKeyEvent:(NSEvent*)event
@@ -782,6 +784,14 @@
             env, jClass, "reportException", "(Ljava/lang/Throwable;)V");
     if ((*env)->ExceptionCheck(env)) return;
 
+    javaIDs.Application.enterNestedEventLoop = (*env)->GetStaticMethodID(
+            env, jClass, "enterNestedEventLoop", "()Ljava/lang/Object;");
+    if ((*env)->ExceptionCheck(env)) return;
+
+    javaIDs.Application.leaveNestedEventLoop = (*env)->GetStaticMethodID(
+            env, jClass, "leaveNestedEventLoop", "(Ljava/lang/Object;)V");
+    if ((*env)->ExceptionCheck(env)) return;
+
     javaIDs.MacApplication.notifyApplicationDidTerminate = (*env)->GetMethodID(
             env, jClass, "notifyApplicationDidTerminate", "()V");
     if ((*env)->ExceptionCheck(env)) return;
@@ -891,11 +901,6 @@
 
     NSAutoreleasePool *glasspool = [[NSAutoreleasePool alloc] init];
     {
-        if (isFullScreenExitingLoop) {
-            // If we ever hit this point (which is unlikely), then we must switch to
-            // using the ui.EventLoop for the internal nested event loop
-            fprintf(stderr, "ERROR in Glass: user's enterNestedEventLoop call while an internal nested event loop is spinning. Please file a bug against Glass.\n");
-        }
         ret = [GlassApplication enterNestedEventLoopWithEnv:env];
     }
     [glasspool drain]; glasspool=nil;
@@ -916,11 +921,6 @@
 
     NSAutoreleasePool *glasspool = [[NSAutoreleasePool alloc] init];
     {
-        if (isFullScreenExitingLoop) {
-            // If we ever hit this point (which is unlikely), then we must switch to
-            // using the ui.EventLoop for the internal nested event loop
-            fprintf(stderr, "ERROR in Glass: user's leaveNestedEventLoop call while an internal nested event loop is spinning. Please file a bug against Glass.\n");
-        }
         [GlassApplication leaveNestedEventLoopWithEnv:env retValue:retValue];
     }
     [glasspool drain]; glasspool=nil;
--- a/modules/graphics/src/main/native-glass/mac/GlassStatics.h	Tue Sep 09 11:01:12 2014 +0200
+++ b/modules/graphics/src/main/native-glass/mac/GlassStatics.h	Tue Sep 09 17:41:46 2014 +0400
@@ -110,6 +110,8 @@
         jmethodID createPixels;
         jmethodID getScaleFactor;
         jmethodID reportException;
+        jmethodID enterNestedEventLoop;
+        jmethodID leaveNestedEventLoop;
     } Application;
     struct {
         jmethodID notifyApplicationDidTerminate;