Snowman
Snowman

Reputation: 32061

Is UIGraphicsBeginImageContext thread safe?

So I've been under the impression that UIGraphicsBeginImageContext is thread safe, and can be called from any thread to create a new CGContextRef that can be used to draw.

However, the current documentation states that

"You should call this function from the main thread of your application only."

However, in the WWDC 2012 session video "Building Concurrent User Interfaces", the speaker shows that you can actually draw in the background, and call that method in the background:

enter image description here

enter image description here

enter image description here

So as you can see, he adds an operation to a _queue (which runs on a BG thread), which calls renderedGraphOfSize, which calls UIGraphicsBeginImageContext. So what's the deal? I am getting some crashes in my app when it comes to drawing in the background, so I don't know why there are confused examples from Apple.

Upvotes: 1

Views: 3821

Answers (2)

EsbenB
EsbenB

Reputation: 3406

To quote from the documentation:

In iOS 4 and later, you may call this function from any thread of your app.

link:http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIKitFunctionReference/Reference/reference.html

Upvotes: 3

Sascha
Sascha

Reputation: 5973

UIGraphicsBeginImageContext definitely is thread safe in iOS 4 and later. WWDC 2012 session videos relate to iOS 6, so maybe you should relate to iOS 6 documentation as well :)

Upvotes: 1

Related Questions