I've made a class that inherits from UIView. I override the setNeedsDisplay method so that I can basically prepare a buffer that will get used by drawRect once its ready (since I don't want to hold up my main thread while doing the leg work). Using dispatch_queue_create() and dispatch_async(), I can get code to send off the buffer preparation to another thread while my app keeps doing other things.
The problem arises when then calling [super setNeedsDisplay]; so that my view's drawRect method gets called.
Basically, drawRect never gets called after the buffer is done with its rendering :
If I make the function not "async", basically write it as so, it works like a charm, except for jamming up the main thread :
Anyone have any insight or passages in the GCD documentation I should pay careful attention to ? I read it, but I don't really understand what I'm missing, it seems rather simple enough, maybe there's a caveat I'm not catching here...
The problem arises when then calling [super setNeedsDisplay]; so that my view's drawRect method gets called.
Basically, drawRect never gets called after the buffer is done with its rendering :
Code:
- (void) setNeedsDisplay
{
self.updateCount++;
dispatch_queue_t queue = dispatch_queue_create("ca.domain.async_draw", NULL);
dispatch_async(queue, ^{
// buffer preparation code here
[super setNeedsDisplay];
});
}
If I make the function not "async", basically write it as so, it works like a charm, except for jamming up the main thread :
Code:
- (void) setNeedsDisplay
{
self.updateCount++;
// buffer preparation code here
[super setNeedsDisplay];
}
Anyone have any insight or passages in the GCD documentation I should pay careful attention to ? I read it, but I don't really understand what I'm missing, it seems rather simple enough, maybe there's a caveat I'm not catching here...