Random image problem has me stumped :(
Random image problem has me stumped :(
- Subject: Random image problem has me stumped :(
- From: Serge Meynard <email@hidden>
- Date: Wed, 23 Mar 2005 16:28:17 -0500
Hello all,
I'm seriously stumped by a random bug I'm having with NSImage. What the code does is pretty simple: it takes a source image and a clipping path specified by an NSBezierPath, and creates a new NSImage with the clipped part of the source image. It does this with the same type of code that has been discussed on this list recently (in fact I myself helped a few others with it). Here is the basic layout of what it does:
[cachedImage release];
cachedImage = [[NSImage alloc] initWithSize:cachedImageSize];
[cachedImage lockFocus];
[curContext saveGraphicsState];
[[NSColor clearColor] set];
NSRectFill(fullBBox);
[[NSColor blackColor] set];
[curContext setShouldAntialias:TRUE];
[contour setLineWidth:1.5];
[contour fill];
[sourceImage compositeToPoint:targetPoint fromRect:adjustedBBox operation:NSCompositeSourceIn];
[contour stroke];
[curContext restoreGraphicsState];
[cachedImage unlockFocus];
This code is used on a bunch of different parts of the source image, and it works perfectly well 99% of the time; but once in a while, I get an empty image. It's never in the same place from one run to another, the places it happens are totally unpredictable, and sometimes I get no bad images at all; but inside of a run, the same part *always* breaks, no matter how many times I rerun the above code. When the broken image is used later, nothing is output. All runs use the same source image and parameters, only the contours change.
The fact that the same part always breaks, combined with the fact that I delete the old image and create a new one, seems to imply that the problem is related to the source data, not the target image. So, I've arranged to break into the debugger specifically when rebuilding a broken image, and checked everything I can think of. The source image is ok, obviously, since it's always the same. I know the contour is ok, because I also draw it elsewhere. All the coordinates used are correct, and changing them around manually has no effect. Changing clearColor to whiteColor has the expected effect on the working images, but none on the broken ones, so it's not a masking issue.
The only thing I know for sure is that something is wrong with the image representation that gets created. As expected, there's only one, an NSCachedImageRep; it gets allocated properly (I think), and its pixel size is correct and non-zero. But if I run the test code below...
[cachedImage lockFocus];
NSBitmapImageRep* bmrep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, width, height)];
...the returned bmrep is nil.
I've had this bug for a while now; I've sat down to look at it several times, and I just can't seem to figure it out. Does anyone have any brilliant insights?
Serge
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden