I have a background task that updates a view. This task calls -setNeedsDisplay to display the view.
It works:
- (void) drawChangesTask;
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (pixels) {
drawChanges((UInt32 *) origPixels, (UInt32 *) pixels, CGBitmapContextGetBytesPerRow(ctx)/4, CGBitmapContextGetHeight(ctx), count--);
if (count < 0) {
count = 150;
}
else
[self performSelectorInBackground:@selector(drawChangesTask) withObject:nil ];
[self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO ];
}
[pool release];
}
This does not work:
- (void) drawChangesTask;
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (pixels) {
drawChanges((UInt32 *) origPixels, (UInt32 *) pixels, CGBitmapContextGetBytesPerRow(ctx)/4, CGBitmapContextGetHeight(ctx), count--);
if (count < 0) {
count = 150;
}
else
[self performSelectorInBackground:@selector(drawChangesTask) withObject:nil ];
[self setNeedsDisplay];
}
[pool release];
}
Does anyone know why? When I say that this does not work, I mean that it runs dozens of iterations, sometimes I see that parts of my image are shifted up or down or completely empty, and then the deagger gives me a " EXC_BAD_ACCESS" somewhere in CoreGraphics.
In addition, if I do not process the auto-advertisement myself, then I get a leak of error messages. I donβt understand why this is so. My drawChanges () does not create any new objects. Here's the error:
2009-08-17 11:41:42.358 BlurApp[23974:1b30f] *** _NSAutoreleaseNoPool(): Object 0xd78270 of class NSThread autoreleased with no pool in place - just leaking
source
share