• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
is lockFocus main thread specific?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

is lockFocus main thread specific?


  • Subject: is lockFocus main thread specific?
  • From: Michael B Johnson <email@hidden>
  • Date: Wed, 14 Nov 2007 22:31:44 -0800

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


  • Follow-Ups:
    • Re: is lockFocus main thread specific?
      • From: Aki Inoue <email@hidden>
    • Re: is lockFocus main thread specific?
      • From: Frank Midgley <email@hidden>
  • Prev by Date: forward class warning
  • Next by Date: Re: What's the easiest way to break on an Obj-C exception?
  • Previous by thread: Re: forward class warning
  • Next by thread: Re: is lockFocus main thread specific?
  • Index(es):
    • Date
    • Thread