NSMessagePort crashes
NSMessagePort crashes
- Subject: NSMessagePort crashes
- From: Stephan Lichtenauer <email@hidden>
- Date: Sun, 23 Jan 2005 17:15:52 +0100
Hi all,
I have written a small test program to use NSMessagePorts/NSPortMessages but at best the message is not received and in the worst case the program crashes with a EXC_BAD_ACCESS.
Below is my code, when I initialize the message as it can be seen with the distantPort, the app crashes, when I init. it with a send port of nil it does not crash but the message is not received nevertheless (push is attached to a button in the IB)... I looked everywhere on the net and in my "Core Mac OS X and Unix Programming" and Cocoa books and could not find much example code that would help, all the code I found looked more or less what I did...
@implementation Test
-(id)init {
[super init];
localPort = [[NSMessagePort alloc] init];
[localPort setDelegate:self]; // do I need this?
distantPort = [[NSMessagePort alloc] init];
[[NSRunLoop currentRunLoop] addPort:localPort forMode:NSDefaultRunLoopMode];
return self;
}
- (void)handlePortMessage:(NSPortMessage *)portMessage {
NSLog(@"Msg received");
}
-(id)sender {
NSPortMessage *msg;
msg = [[NSPortMessage alloc] initWithSendPort:distantPort
receivePort:localPort
components:nil];
[msg setMsgid:10];
[msg sendBeforeDate:[NSDate distantPast]];
}
@end
Anybody any idea?
Thanks a lot!
Stephan
PS I know there are memory leaks but I wanted to keep the code as simple as possible...
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden