Re: Help with crash
Re: Help with crash
- Subject: Re: Help with crash
- From: Ulrik Sverdrup <email@hidden>
- Date: Fri, 14 Mar 2003 16:39:10 +0100
Oh, I din't think this mail was sent, but apparently it was sent to
you, but not the list. I'll submit this answer to the list, though.
This question was answered recently in the mailing list, or atleast I
found something here that helped me out.. a search on NSThread might
have helped you out.
Anyway, here's how my applicaton solves the task:
I have a thread that does the pre-drawing that ends like this;
...
[self performSelectorOnMainThread:@selector(drawingDidFinishNowDraw)
withObject:nil waitUntilDone:NO];
[pool release];
}
It simply sends a message to perform the method
"drawingDidFinishNowDraw" , defined in the same class, in the mail
thread. Note that including (performSelectorOnMainThread:) makes your
app require jaguar to work. If you don't want your application to
require jaguar, there is a workaround but I don't know how you do it.
My subthread exits and "drawingDidFinishNowDraw" runs:
- (id)drawingDidFinishNowDraw
{
if ([self lockFocusIfCanDraw])
{
// draw
...
And thus, the drawing is brought back to the mail thread.
>
>> Ulrik Sverdrup, email@hidden
fredagen den 14 mars 2003 kl 13.25 skrev Gilbert Mackall:
>
Thanks for you help. A further question: How can I have my secondary
>
thread pass a message to the main thread that it needs to draw?
>
>
>
>
On Wednesday, March 12, 2003, at 12:16 PM, Ulrik Sverdrup wrote:
>
>
>
>
> You cannot write to the same View from more than one thread at a
>
> time. Many times it works to let a secondary Thread draw, but when it
>
> accidentally draws at the same time drawRect: is called in the main
>
> thread, it crashes. You'll have to let the secondary thread do the
>
> processing, but let the main thread draw it.
>
>
>
> Ulrik Sverdrup, email@hidden
>
>
>
> onsdagen den 12 mars 2003 kl 14.12 skrev Gilbert Mackall:
>
>> I have a problem with an application that I am writing. After adding
>
>> threading, a routine that draws to an NSView randomly causes a
>
>> crash. I can't make heads or tails out of the crash log, looking for
>
>> some help...
>
>>
>
>
>
>
>
>
>
>
Gilbert Mackall
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.