Re: [NSImage lockFocus] and threads
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