changeset 4895:c0b98811b1fc jdk7u4-b200

7125267: TrayIcon removal test invariably crashes on System.exit after successful completion Reviewed-by: anthony
author leonidr
date Thu, 29 Dec 2011 20:40:15 +0300
parents 546eea5433b1
children bd7524f94558
files src/macosx/native/sun/awt/CTrayIcon.m
diffstat 1 files changed, 20 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/native/sun/awt/CTrayIcon.m	Thu Dec 29 17:35:30 2011 +0300
+++ b/src/macosx/native/sun/awt/CTrayIcon.m	Thu Dec 29 20:40:15 2011 +0300
@@ -71,7 +71,15 @@
     JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
     JNFDeleteGlobalRef(env, peer);
 
-    [view release];    
+    [[NSStatusBar systemStatusBar] removeStatusItem: theItem];
+
+    // Its a bad idea to force the item to release our view by setting
+    // the item's view to nil: it can lead to a crash in some scenarios.
+    // The item will release the view later on, so just set the view's image
+    // to nil since we are done with it.
+    [view setImage: nil];
+    [view release];
+
     [theItem release];
 
     [super dealloc];
@@ -97,6 +105,9 @@
         [imagePtr setSize: scaledSize];
     }
     
+    CGFloat itemLength = scaledSize.width + 2.0*kImageInset;
+    [theItem setLength:itemLength];
+
     [view setImage:imagePtr];
 }
 
@@ -137,10 +148,9 @@
     [image release];   
     image = anImage;
 
-    CGFloat itemLength = [anImage size].width + 2.0*kImageInset;   
-    [trayIcon.theItem setLength:itemLength];
-
-    [self setNeedsDisplay:YES];
+    if (image != nil) {
+        [self setNeedsDisplay:YES];
+    }
 }
 
 - (void)menuWillOpen:(NSMenu *)menu 
@@ -156,6 +166,10 @@
 
 - (void)drawRect:(NSRect)dirtyRect
 {
+    if (image == nil) {
+        return;
+    }
+
     NSRect bounds = [self bounds];
     NSSize imageSize = [image size];
 
@@ -270,7 +284,7 @@
 AWT_ASSERT_NOT_APPKIT_THREAD;
 
     AWTTrayIcon *icon = jlong_to_ptr(model);
-    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
         [icon setImage:jlong_to_ptr(imagePtr) sizing:autosize];
     }];