Can't catch ObjC exceptions in nsColorPicker.mm when building with the 10.11 SDK

NEW
Unassigned

Status

()

Core
Widget: Cocoa
P3
normal
8 months ago
6 months ago

People

(Reporter: mstange, Unassigned)

Tracking

(Depends on: 1 bug)

Trunk
All
Mac OS X
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox57 affected)

Details

Attachments

(2 attachments)

(Reporter)

Description

8 months ago
Steps to reproduce:
 1. Create a Firefox build with the 10.11 SDK.
 2. Open a color picker by clicking the button in the testcase.
 3. In the third pane, choose "Developer" from the list and click a color in the list below, e.g. controlHighlightColor.
 4. Crash.

From the crash report:

Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -getRed:green:blue:alpha: not valid for the NSColor NSNamedColorSpace System controlLightHighlightColor; need to first convert colorspace.'
Performing @selector(colorChanged:) from sender NSColorPanel 0x1338e5200
terminating with uncaught exception of type NSException
abort() called

Application Specific Backtrace 1:
0   CoreFoundation  0x00007fffbbf9c2cb __exceptionPreprocess + 171
1   libobjc.A.dylib 0x00007fffd0dac48d objc_exception_throw + 48
2   CoreFoundation  0x00007fffbc01ac3d +[NSException raise:format:] + 205
3   XUL             0x0000000115515724 _ZN13nsColorPicker23GetHexStringFromNSColorEP7NSColorR9nsAString + 52
[...]

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib   0x00007fffd17c0d42 __pthread_kill + 10
1   libsystem_pthread.dylib  0x00007fffd18ae457 pthread_kill + 90
2   libsystem_c.dylib        0x00007fffd1726420 abort + 129
3   libc++abi.dylib          0x00007fffd027994a abort_message + 266
4   libc++abi.dylib          0x00007fffd029ec2f default_terminate_handler() + 267
5   libobjc.A.dylib          0x00007fffd0dae6fe _objc_terminate() + 103
6   libc++abi.dylib          0x00007fffd029bd49 std::__terminate(void (*)()) + 8
7   libc++abi.dylib          0x00007fffd029b7be __cxa_throw + 121
8   libobjc.A.dylib          0x00007fffd0dac5b6 objc_exception_throw + 345
9   com.apple.CoreFoundation 0x00007fffbc01ac3d +[NSException raise:format:] + 205
10  XUL                      0x0000000115515724 nsColorPicker::GetHexStringFromNSColor(NSColor*, nsAString&) + 52 (nsColorPicker.mm:148)
[...]


The code in nsColorPicker.mm does this:

> /* static */ void
> nsColorPicker::GetHexStringFromNSColor(NSColor* aColor, nsAString& aResult)
> {
>   CGFloat redFloat, greenFloat, blueFloat;
> 
>   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];
>   }

We're crashing in the *first* call to -[NSColor getRed:green:blue:alpha:], which is *inside* the @try block. So there shouldn't be an "uncaught exception" here.
(Reporter)

Comment 1

8 months ago
Created attachment 8899598 [details]
testcase
(Reporter)

Comment 2

8 months ago
It seems to be the -no_compact_unwind linker flag that's causing unwinding to fail.

I'm no longer certain that this has to do with the SDK being used.
Depends on: 1290972
(Reporter)

Comment 3

8 months ago
Created attachment 8899620 [details]
minimal objective C++ testcase

Save as main.mm, and compile with either

> clang++ main.mm -o main -framework Cocoa
or
> clang++ main.mm -o main -framework Cocoa -Wl,-no_compact_unwind

and then run ./main .

When compiled without -Wl,-no_compact_unwind, the exception is caught correctly. When compiling with -Wl,-no_compact_unwind, the process is terminated when the exception is thrown.
(Reporter)

Updated

8 months ago
Attachment #8899620 - Attachment mime type: text/x-troff-mm → text/plain
(Reporter)

Comment 4

8 months ago
I don't understand why our regular Nightly builds don't run into this crash.

Updated

6 months ago
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.