changeset 2838:df3b6b3fdef5

RT-28781 Mac: JVM crashes when screen resolution is changed Reviewed-by: Anthomy, Steve
author Petr Pchelko <petr.pchelko@oracle.com>
date Tue, 12 Mar 2013 14:59:02 +0400
parents 98c92b4b238d
children d45b7c33204d
files glass/glass-lib-macosx/src/GlassTimer.m
diffstat 1 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/glass/glass-lib-macosx/src/GlassTimer.m	Tue Mar 12 08:39:25 2013 +0100
+++ b/glass/glass-lib-macosx/src/GlassTimer.m	Tue Mar 12 14:59:02 2013 +0400
@@ -119,18 +119,20 @@
     {
         GlassTimer *timer = (GlassTimer*)displayLinkContext;
         
-        if (timer->_env == NULL) 
+        jint error = (*MAIN_JVM)->AttachCurrentThreadAsDaemon(MAIN_JVM, (void **)&timer->_env, NULL);
+        if (error == 0)
         {
-            jint error = (*MAIN_JVM)->AttachCurrentThreadAsDaemon(MAIN_JVM, (void **)&timer->_env, NULL);
-            if (error != 0)
+            if (timer->_runnable != NULL)
             {
-                NSLog(@"ERROR: Glass could not attach CVDisplayLink _thread to VM, result:%d\n", (int)error);
+                (*timer->_env)->CallVoidMethod(timer->_env, timer->_runnable, jRunnableRun);
             }
-        }
-        
-        if (timer->_runnable != NULL)
-        {
-            (*timer->_env)->CallVoidMethod(timer->_env, timer->_runnable, jRunnableRun);
+
+            error = (*MAIN_JVM)->DetachCurrentThread(MAIN_JVM);
+            if (error != JNI_OK) {
+                NSLog(@"ERROR: Glass could not detach CVDisplayLink _thread to VM, result:%d\n", (int)error);
+            }
+        } else {
+            NSLog(@"ERROR: Glass could not attach CVDisplayLink _thread to VM, result:%d\n", (int)error);
         }
     }