iOS 8 changed UIImage imageNamed:, breaking its thread safety

Originator:adamjernst
Number:rdar://18541885 Date Originated:10/3/2014
Status:Duplicate Resolved:
Product:iOS SDK Product Version:8.0
Classification:Bug Reproducible:Always
 
The docs for [UIImage +imageNamed:] were edited in iOS 8 to note "You can not assume that this method is thread safe."

Our app relied on [UIImage +imageNamed:] being threadsafe, as it was in all recent versions of iOS. Since this regression was introduced in iOS 8, our app has experienced many crashes due to this issue.

WORKAROUNDS:
- dispatch_sync to the main queue to call [UIImage imageNamed:]. Not viable in general as the calling thread may be holding a lock that the main thread is blocked trying to acquire, triggering deadlock. This also has extremely poor performance.
- Use CGDataProvider and CGImage. Not viable with asset catalogs, which are an opaque file format.
- Stop using asset catalogs (but this presumes [UIImage imageNamed:] is threadsafe for non-asset-catalog images, which the docs now specifically deny)
- Load all images that may be needed off-main-thread on the main queue up front. Not practical as it may not be possible to predict which images are needed off the main thread. Loading the entire set of images is prohibitively expensive.

Steps to Reproduce:
1. Call [UIImage +imageNamed:] off the main thread.
2. Your app will crash with the attached crash.txt intermittently (but frequently enough that it's a major issue for us).

Expected Results:
We expect an API exposed that allows loading asset catalog UIImages without blocking the main thread.

Actual Results:
No way to load asset catalog UIImages off the main queue at all.

Comments

Marked as "Duplicate of 17672105"

By adamjernst at Oct. 14, 2014, 5:08 p.m. (reply...)

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!