• 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
Re: [NSImage lockFocus] and threads
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [NSImage lockFocus] and threads


  • Subject: Re: [NSImage lockFocus] and threads
  • From: Aki Inoue <email@hidden>
  • Date: Sat, 21 Jul 2001 01:03:03 -0700

Michael,

That exception could be raised with either of the two reasons.

1) The size of the image is either 0.0 or ridiculously large number
2) Or, AppKit is somehow screwed up

With 2) case, you should get a log message like "No cache for representation" in the console.

If you're not seeing it, then, maybe your functions is passed 0 for iconWidth.

Aki

On 2001.07.21, at 00:43, Michael Horn wrote:

Adding the following line to the NS_HANDLER:

NSLog(@"exception name: %@ reason: %@ userInfo: %@", [localException name], [localException reason], [localException userInfo]);

results in:

exception name: NSImageCacheException reason: Can't cache image userInfo: (null)

What I really don't understand is I get this expection for different files at different times. If it was just a couple files, then it might make some sense. Any ideas?

Thanks again.


At 12:10 AM -0700 7/21/01, Aki Inoue wrote:
Your code looks good.

What kind of exception you're getting ?
What about the description string attached to the exception instance ?

Aki

On 2001.07.21, at 00:02, Michael Horn wrote:

Since this is the case, why would lockFocus through an exception then?

Here is the bit of code where I am using lockFocus:

- (NSImage*) resampleImage:(NSImage*)image toIconWidth:(int)iconWidth {
NSSize size;
NSSize thumbnailSize;
NSPoint origin;
NSImage *thumbnail;
NS_DURING
size = [image size];
if (size.width > size.height) {
thumbnailSize = NSMakeSize(iconWidth, iconWidth * size.height / size.width);
} else {
thumbnailSize = NSMakeSize(iconWidth * size.width / size.height, iconWidth);
};
origin.x = 0;
origin.y = 0;
thumbnail = [[NSImage alloc] initWithSize: thumbnailSize];
[thumbnail lockFocus];
//[image compositeToPoint: origin operation: NSCompositeCopy];
[image drawInRect: NSMakeRect(0, 0, thumbnailSize.width, thumbnailSize.height)
fromRect: NSMakeRect(0, 0, size.width, size.height)
operation: NSCompositeCopy fraction: 1.0];
[thumbnail unlockFocus];
NS_HANDLER
#if DEBUG
[debugLock lock];
NSLog(@"Exception Handled");
[debugLock unlock];
#endif
NS_ENDHANDLER
return thumbnail;
}


This method is called as a sub routine of a main method that was broken of as a thread. When I have several threads going, I get exceptions for about 10% of the calls to this function.

Any help with this would be greatly appreciated.




At 11:28 PM -0700 7/20/01, Aki Inoue wrote:
For both NSView & NSImage, the focus stack is provided for each thread.

So, you can safely lockFocus from multiple thread.

Aki

On 2001.07.20, at 22:51, Michael Horn wrote:

Can multiple threads have different lockFocus calls simultaneously or will one lockFocus called before a unlockFocus cause an exception to be raised? Thanks.
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


  • Follow-Ups:
    • Re: [NSImage lockFocus] and threads
      • From: Michael Horn <email@hidden>
References: 
 >Re: [NSImage lockFocus] and threads (From: Michael Horn <email@hidden>)

  • Prev by Date: Re: [NSImage lockFocus] and threads
  • Next by Date: Re: A question about static typing
  • Previous by thread: Re: [NSImage lockFocus] and threads
  • Next by thread: Re: [NSImage lockFocus] and threads
  • Index(es):
    • Date
    • Thread