Re: Aqua animations drawing from separate thread
Re: Aqua animations drawing from separate thread
- Subject: Re: Aqua animations drawing from separate thread
- From: Frederik Slijkerman <email@hidden>
- Date: Sat, 15 Aug 2009 20:24:53 +0200
The problem is that of course, you don't know that in general, so it's a
potentially difficult-to-find bug that could happen anywhere in your
code. For example, I now have a button that's just above a view with
complex drawing, so the border of the button overlaps with that view and
causes it to redraw.
I definitely agree with Dave Keck that it seems like a gross oversight
on Apple's part to handle Aqua animations from a secondary thread --
that should have been done with a timer from the main thread. There's
nothing in the drawRect documentation that would suggest this, I found
it out using the debugger. (And yes, it does cause a crash in my code.)
I briefly tried calling the drawing code via [NSObject
performSelectorOnMainThread] but that of course causes an immediate
deadlock. Looks like the only solution is to do all complex drawing to
an off-screen bitmap if drawRect is called from the main thread, and
just draw that bitmap if drawRect is called from another thread. But
this is slower and consumes more memory.
Best regards,
Frederik Slijkerman
BravoBug Software wrote:
> If you don't need to do secondary-thread drawing in your view, you
> don't have to. You can check which thread is sending the -drawRect
> method. Allow the subviews such as the aqua button to draw themselves,
> and skip over any thread-unsafe custom -drawRect stuff in your
> superview.
>
> The only thing you would need to redraw in your superview is the tiny
> rect surrounding the pulsing blue aqua button. I can't really imagine
> what kind of complex thread-unsafe stuff would be going on in the tiny
> spaces around the rounded-corner edges of the button. Seems like that
> would typically be transparent, a background color/pattern, or
> something similar. You should be able to supply that minimal amount of
> drawing in a thread-safe fashion without too much difficulty.
>
> On Fri, Aug 14, 2009 at 8:45 AM, Frederik
> Slijkerman<email@hidden> wrote:
>> Hi,
>>
>> Another question... I've noticed that Aqua animations, for example the
>> pulsing default button, are implemented via a separate thread, which
redraws
>> the button repeatedly. This also causes the view (for example a
custom view
>> that I wrote myself) that contains the button to receive a drawRect
message,
>> of course.
>>
>> The problem is that this drawRect message is sent from the separate
thread,
>> which means that drawing in all my custom views needs to be thread-safe.
>> This is a huge pain.
>>
>> Is there any way around this? Are you all always writing thread-safe
>> drawRect handlers? It seems like a huge responsibility to make sure this
>> will always work correctly...
>>
>> Thanks in advance!
>>
>> Best regards,
>> Frederik Slijkerman
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden