Re: drawing NOW in a callback, boom!
Re: drawing NOW in a callback, boom!
- Subject: Re: drawing NOW in a callback, boom!
- From: Paul Cezanne <email@hidden>
- Date: Wed, 5 Jun 2002 12:49:04 -0400
I'm the original poster in this thread and there has been a lot of talk about how safe or unsafe threaded modifications to the UI are.
I believe I _have_ followed the guidelines, all my drawing calls are via NSBezierPath, which is allegedly safe.
I'm still no closer to a solution.
Just in case it was unsafe, I'm trying to move all my drawing out the "callback" thread. First I tried
[NSApp sendAction:@selector(display) to:nil from:NSApp];
which seemed to be equivalent to call display directly, it happened in my thread (and crashed just the same). A little more reading suggest that I should post an event from my thread. So put together these calls in my thread:
NSEvent* event = [NSEvent otherEventWithType:NSApplicationDefined
location: NSMakePoint(0,0)
modifierFlags:0
timestamp:0
windowNumber:targetWindowNumber
context:nil
subtype:targetEventSubType
data1:(int)0
data2:(int)0];
[NSApp postEvent:event atStart:YES];
I put this global in my view:
int targetWindowNumber;
- (void)viewDidMoveToWindow
{
targetWindowNumber = [[self window] windowNumber];
}
so I can get the windowNumber in my C callback. Then I subclassed my window to catch the event I posted so I can force the view to redraw:
- (void)sendEvent:(NSEvent *)theEvent
{
if ([theEvent type]==NSApplicationDefined) {
if ([theEvent subtype] == targetEventSubType) {
[self display];
return;
}
}
[super sendEvent:theEvent];
}
Funny thing is, I NEVER get the event. I know it is hooked up correctly because if I put a breakpoint, say, on the first line, I see that I'll get a left mouse click, for example, so I know my subclassing is correct.
I've read a lot on this but still haven't found the answer. All I want to do is modify the UI in response to a C callback on a thread (pthread), this ought not to be difficult.
(Oh, and I did add the NSThread calls to my app, since I was using pthreads, didn't help.)
I appreciate any help, thanks.
Paul
_______________________________________________
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.