Bug 1293593 - Fix crash due to an Objective-C exception when calling getRed:green:blue:alpha on an NSColor instance with an incompatible NSColorSpace. r=mstange, a=sledru
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Fri, 19 Aug 2016 23:17:58 -0400
changeset 342446 c56047b7ac0dabf7e7ea4492e2da12fc92981691
parent 342445 e66d206c851c7d6410a2eb858e45e4d85c77796c
child 342447 cbe685bc5bc45cf9aef4f19dcca24dacc4ad4bb8
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, sledru
bugs1293593
milestone49.0
Bug 1293593 - Fix crash due to an Objective-C exception when calling getRed:green:blue:alpha on an NSColor instance with an incompatible NSColorSpace. r=mstange, a=sledru
widget/cocoa/nsColorPicker.mm
--- a/widget/cocoa/nsColorPicker.mm
+++ b/widget/cocoa/nsColorPicker.mm
@@ -131,17 +131,24 @@ nsColorPicker::GetNSColorFromHexString(c
 
   return [NSColor colorWithDeviceRed: red green: green blue: blue alpha: 1.0];
 }
 
 /* static */ void
 nsColorPicker::GetHexStringFromNSColor(NSColor* aColor, nsAString& aResult)
 {
   CGFloat redFloat, greenFloat, blueFloat;
-  [aColor getRed: &redFloat green: &greenFloat blue: &blueFloat alpha: nil];
+
+  NSColor* color = aColor;
+  @try {
+    [color getRed:&redFloat green:&greenFloat blue:&blueFloat alpha: nil];
+  } @catch (NSException* e) {
+    color = [color colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];
+    [color getRed:&redFloat green:&greenFloat blue:&blueFloat alpha: nil];
+  }
 
   nsCocoaUtils::GetStringForNSString([NSString stringWithFormat:@"#%02x%02x%02x",
                                        (int)(redFloat * 255),
                                        (int)(greenFloat * 255),
                                        (int)(blueFloat * 255)],
                                      aResult);
 }