Random image problem solved, but...
Random image problem solved, but...
- Subject: Random image problem solved, but...
- From: Serge Meynard <email@hidden>
- Date: Thu, 24 Mar 2005 12:46:23 -0500
Thanks to a tip from John Pannell, I finally found the problem... Since
I'm creating a lot of offscreen images, and since each one ends up with
a cached representation in a potentially *shared* offscreen window, it
looks like at some point the offscreen window gets messed up or not
resized properly or whatever, leading to my empty image problem. Adding
this line fixed the problem:
[cachedImage setCachedSeparately:YES];
That line forces Cocoa to cache each image in a separate window, so the
bug vanishes. Unfortunately, that line forces Cocoa to cache each image
in a separate window, so I get tons of them, which I'm sure is a Bad
Thing (it certainly is slower). So... I decided to switch to
NSBitmapImageReps.
Instead of letting Cocoa create a rep by itself, I tried creating a
bitmap rep, adding it to the image, then locking focus and drawing as I
did before. I also took care to call setCachedMode:NSImageCacheNever so
the image would not get cached. Unfortunately, that method is a bit
misleading: it apparently prevents caching when *rendering* the image,
but not when *writing to* the image! After lockFocus/draw/unlockFocus,
my handcrafted bitmap rep had vanished and become an NSCachedImageRep
again. Sigh.
So I changed the code again. Just as originally, I let Cocoa create its
own image rep. After I'm done drawing the image, I use
initWithFocusedRect: to extract a bitmap rep from the image, then
delete the NSCachedImageRep, and reinsert the bitmap rep. Combined with
setCachedMode:NSImageCacheNever and setCachedSeparately:YES (which is
still required), I finally have no broken images (and no wasted
offscreen windows).
The only thing that still bothers me is that this whole process feels a
bit convoluted. Did I miss a simpler way to do it?
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