Getting a predefined UIColor with a NSInvocation crashes the app

Originator:abarisain
Number:rdar://27017942 Date Originated:06/26/2016
Status:Open Resolved:
Product:iOS SDK Product Version:iOS 10.0 14A5261u
Classification:Crash Reproducible:Always
 
chained code (meaning in the same scope) will not crash. You have to get out of the scope to trigger the subsequent crash: once you've did that, even a "po [UIColor redColor]" in lldb will trigger an exception

"Warming up" the cached colors using standard calls make the issue disappear.

Retaining the variable by marking the NSInvocation output pointer as __unsafe_retained and then copying it in a "normal" variable also fixes the issue. While this may have been the right way to do it all along,  it doesn't seem right for UIKit to crash like that.

Steps to Reproduce:
1. Write some code that calls the equivalent of "[UIColor redColor]"  using NSInvocation
2. Make sure you don't mark the result variable with "__unsafe_unretained"
3. Call it twice

Expected Results:
The wanted UIColor is returned every time

Actual Results:
The UIColor is returned the first time.
On the second run, the app crashes with EXC_BAD_ACCESS
Turning on NSZombies will show that a call to a deallocated object occurs.

Version:
Xcode Version 8.0 beta (8S128d) - iOS 10.0 14A5261u

Notes:
Tested under an iOS 8.4 simulator with Xcode 8 : doesn't crash
Tested under an iOS 9 simulator with Xcode 7 : doesn't crash.

Only crashes on a iOS 10 simulator with Xcode 8

I've yet to test on a real device.

Sample Xcode project attached

(Also note that it's never code I would use in a production app, it just occurred during some dev tests ;) )

Configuration:
OSX El Capitan, Macbook Pro 15", running the Xcode 8 iOS Simulator

Attachments:
'ColorCrashReproTest.zip' was successfully uploaded.

Comments

This issue has been verified as resolved and can be closed.

Fixed in iOS 10 beta 3

Reproduced this bug on an iPad Mini 2 running iOS 10 (14A5261v)


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!