Re: is lockFocus main thread specific?
Re: is lockFocus main thread specific?
- Subject: Re: is lockFocus main thread specific?
- From: Michael B Johnson <email@hidden>
- Date: Thu, 15 Nov 2007 10:04:16 -0800
On Nov 15, 2007, at 9:10 AM, Aki Inoue wrote:
Michael,
You can safely use -lockFocus from any threads.
If you're seeing some issues, please file a bug with specific steps
to reproduce.
done. Radar 5602409
Thanks,
Aki
On 2007/11/14, at 22:31, Michael B Johnson wrote:
This is a Leopard only question.
I have a small test app I've been working on that runs on Leopard
in 64 bit that uses NSOperation to do its threading, and am
crashing in code that looks like the following. Unfortunately,
when I run this on several hundred images, it, occasionally (but
consistently) crashes in the drawInRect:.
Now perhaps this has to run in the main thread, but I don't seem to
remember that as a restriction (but I could just be blocking that
info). I know that I could use ImageIO to get the thumbnail (and
probably will), but I have to read the NSImage anyway, since I'm
about to hand this image to QTKit, which only takes an NSImage.
Here's what the stack trace looks like:
#0 0x805e7a3e in objc_msgSend
#1 0x83d980c6 in _NXAllocateImageCache
#2 0x83d97720 in -[NSCachedImageRep
_initWithSize:depth:separate:alpha:allowDeep:]
#3 0x83d9a9e4 in -[NSImage _focusOnCache:creatingWithSizeInPixels:]
#4 0x83d9a3fc in -[NSImage
_cacheRepresentation:toSizeInPixels:stayFocused:]
#5 0x83d9340f in -[NSImage drawInRect:fromRect:operation:fraction:]
and here's the code in the -main of the operation:
NSImage* img = [[NSImage alloc] initWithContentsOfURL:url];
// make a thumbnail:
NSSize fullSize = [img size];
NSRect srcRect = NSMakeRect(0, 0, fullSize.width, fullSize.height);
NSSize newSize;
CGFloat aspectRatio = fullSize.width / fullSize.height;
if (aspectRatio < 1.0) {
newSize.height = 256;
newSize.width = newSize.height / aspectRatio;
} else {
newSize.width = 256;
newSize.height = newSize.width / aspectRatio;
}
NSRect dstRect = NSMakeRect(0, 0, newSize.width, newSize.height);
NSImage* thumbnail = [[[NSImage alloc] initWithSize:newSize]
autorelease];
[thumbnail lockFocus];
[img drawInRect:dstRect fromRect:srcRect
operation:NSCompositeCopy fraction:1.0f];
[thumbnail unlockFocus];
_______________________________________________
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
_______________________________________________
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