Am 30.03.2008 um 17:01 schrieb Adam R. Maxwell:

On Mar 30, 2008, at 6:10 AM, Thomas Engelmeier wrote:

On 29.03.2008, at 18:54, Adam R. Maxwell wrote:

Drawing into an NSImage is explicitly documented to be thread safe in the article you linked to, and each thread has its own graphics context. The post I linked to does indicate that you might want to use [image setCacheMode:NSImageCacheNever]. If your goal is just to get an NSBitmapImageRep from a file, it's probably easier just to use +imageRepWithContentsOfFile:.

While it is documented to be thread save you might get crashes later when an NSBitmapImageRep created by drawing into from an secondary thread gets drawn itself. The crash occurs when the image tries to access an NULL (offscreen) window context (it probably was originally drawn into).

Tried to debug that on 10.5.2 (and simply worked around)...

That's interesting. Was it an NSBitmapImageRep or NSImage/ NSCachedImageRep? I didn't think a bitmap context would be associated with a window context like that. Either way it doesn't sound good, though.



Well, actually an NSTIFFImageRep. The crashing code (other thread, much later, ...):

NSData *data = [anImage TIFFRepresentationUsingCompression:NSTIFFCompressionLZW factor:1.0];

/* gives an crash in
FREED(id): message _tryLockViewHierarchyForModification sent to freed object=0xeee5b40
#1  0x90063ef0 in __objc_error ()
#2  0x900628f7 in _freedHandler ()
#3  0x92f807c2 in _NXAllocateImageCache ()
#4  0x92f83458 in -[NSCachedImageRep window] ()
#5  0x92f83202 in -[NSImage _getCacheWindow:andRect:forRep:] ()
#6 0x9307fa8e in -[NSImage TIFFRepresentationUsingCompression:factor:] () #7 0xcf13d7b4 in -[iMBMoviesView saveImageForPath:] (self=0xee42830, _cmd=0xcf1528f6, imagePath=0xeef4e60) at /Development/Sources/ googlecode/imedia-nsview-branch/branch20080218/iMBMoviesView.m:225
*/

The creation code (two variants):

/*      TE: work around an NSImageCache bug !?! */
        [image setScalesWhenResized:YES];
        [image setSize:newSize];

#if 0   
        NSData *tiffData = [image TIFFRepresentation];
NSBitmapImageRep *tiffRep = [NSBitmapImageRep imageRepWithData:tiffData]; NSImage *newImage = [[NSImage allocWithZone:[self zone]] initWithSize:newSize];

    [newImage setScalesWhenResized:YES];
        [newImage addRepresentation:tiffRep];
#else   
NSImage *newImage = [[NSImage allocWithZone:[self zone]] initWithSize:newSize];
    [newImage setScalesWhenResized:YES];
        [newImage setDataRetained:YES];
//?    [newImage setCachedSeparately:YES];
    [newImage lockFocus];
[image drawInRect:NSMakeRect(0.0f, 0.0f, newSize.width, newSize.height)
             fromRect:NSMakeRect(0.0f, 0.0f, size.width, size.height)
            operation:NSCompositeCopy fraction:1.0f];
    [newImage unlockFocus];
#endif
    return [newImage autorelease];

Regards,
        Tom_E
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to