Re: NSImage drawInRect deadlock
Re: NSImage drawInRect deadlock
- Subject: Re: NSImage drawInRect deadlock
- From: Aaron Tuller <email@hidden>
- Date: Mon, 08 Aug 2016 14:54:30 -0700
On Aug 8, 2016, at 1:48 PM, Jens Alfke <email@hidden> wrote:
> On Aug 8, 2016, at 12:46 PM, Aaron Tuller <email@hidden <mailto:email@hidden>> wrote:
>>
>> Search for NSImage here:
>>
>> https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html#//apple_ref/doc/uid/10000057i-CH12-126728 <https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html#//apple_ref/doc/uid/10000057i-CH12-126728>
>>
>
> All it says about NSImage is: "One thread can create an NSImage object, draw to the image buffer, and pass it off to the main thread for drawing. The underlying image cache is shared among all threads.”
>
> So it sounds like the problem isn’t the new NSImage but the existing one being drawn into it. It might help to get the NSImage’s imageRep on the main thread and then pass that to the background thread.
>
> (I’ve got some similar code in one of my apps that creates NSImages on a parallel dispatch queue and draws into them, but it only draws text, not any pre-existing images. This code works fine even with dozens of tasks at a time.)
Well it also says:
"The following classes and functions are generally not thread-safe. In most cases, you can use these classes from any thread as long as you use them from only one thread at a time."
and then lists NSImage. That's why a serial queue would probably work...or using something else like passing around an image rep as Jens suggests and drawing it to a local NSGraphicsContext backed by a NSBitmapImageRep.
-aaron
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden