NSCoding of custom object instance variables
NSCoding of custom object instance variables
- Subject: NSCoding of custom object instance variables
- From: Rick Hoge <email@hidden>
- Date: Tue, 13 Jul 2004 19:04:47 -0400
I'm trying to pass a copy of an object (a plugin) as an argument in a
distributed objects method call. The object in question has several
instance variables, including one that is a custom NSDocument subclass.
I have implemented the NSCoding protocol for all of the objects in
question, as well as the replacementObjectForPortCoder: method required
so that encodeWithCoder actually gets called. Now, as expected, the
encodeWithCoder: method is being called for the object that is passed
as a method argument. That method is *not* being called for the
NSDocument subclass instance variable, however, and I can't figure out
why not.
The coding for the plugin method (the one which *is* run) looks like
this:
-(void)encodeWithCoder:(NSCoder*)coder {
NSLog(@"Encoding MyPlugin..."); // This appears in the system log
[coder encodeValueOfObjCType:@encode(BOOL) at:&isInteractive];
[coder encodeValueOfObjCType:@encode(BOOL) at:&isThreaded];
[coder encodeObject:srcDocument]; // srcDocument's encodeWithCoder:
does not get run, for some reason
}
I'd have thought the last line of code would result in srcDocument's
encodeWithCoder method getting run, but logging messages (or lack of
them) indicate that it is not being used. The document subclass _does_
have a replacementObjectForPortCoder: method - maybe this is the
problem?
Thanks for any suggestions - I'm getting nasty crashes because the
document does not seem to be correctly passed to the remote object.
For what it's worth, the crash logs look like this (app only crashes if
I try to access the document object - other ivars seem ok):
Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000000
Thread 0 Crashed:
0 libobjc.A.dylib 0x908311f4 objc_msgSend + 0x14
1 com.apple.Foundation 0x90a12014 -[NSInvocation invalidate] +
0x54
2 com.apple.Foundation 0x90a02c4c -[NSInvocation dealloc] + 0x24
3 com.apple.Foundation 0x909f15d4 NSPopAutoreleasePool + 0x164
4 com.apple.Foundation 0x90a74abc NSLog + 0x1c
5 MyAppController.ob 0x004f9090 -[MyAppController
runPluginForClient:] + 0x7c (MyAppController.m:450)
6 libobjc.A.dylib 0x90836734 objc_msgSendv + 0xb4
7 com.apple.Foundation 0x909fabf0 -[NSInvocation invoke] + 0x374
8 com.apple.Foundation 0x90a20954 -[NSConnection
dispatchInvocation:] + 0xf4
9 com.apple.Foundation 0x90a140bc -[NSConnection
handleRequest:sequence:] + 0x3e8
10 com.apple.Foundation 0x90a1c760 -[NSConnection
handlePortCoder:] + 0x160
11 com.apple.Foundation 0x90a17888 -[NSConcretePortCoder
dispatch] + 0x54
12 com.apple.Foundation 0x90abca3c -[NSSocketPort
_handleMessage:from:socket:] + 0x358
13 com.apple.Foundation 0x90abe6c4 __NSFireSocketData + 0x24c
14 com.apple.CoreFoundation 0x901a28fc __CFSocketPerform + 0x260
15 com.apple.CoreFoundation 0x90193d38 __CFRunLoopDoSources0 + 0x1fc
16 com.apple.CoreFoundation 0x901915f0 __CFRunLoopRun + 0x1b0
17 com.apple.CoreFoundation 0x90195f1c CFRunLoopRunSpecific + 0x148
18 com.apple.Foundation 0x90a03f84 -[NSConnection
sendInvocation:] + 0x560
19 com.apple.Foundation 0x909fcfd0
-[NSObject(NSForwardInvocation) forward::] + 0x198
20 libobjc.A.dylib 0x90836810 _objc_msgForward + 0xb0
21 MyAppController.ob 0x004f9000 -[MyAppController
launchPluginOnRemoteServer:] + 0x24c (MyAppController.m:427)
22 com.apple.AppKit 0x92e77ac0 -[NSApplication
sendAction:to:from:] + 0x6c
23 com.apple.AppKit 0x92e7e844 -[NSControl sendAction:to:] +
0x60
24 com.apple.AppKit 0x92eb8abc -[NSCell _sendActionFrom:] +
0x9c
25 com.apple.AppKit 0x92e58500 -[NSCell
trackMouse:inRect:ofView:untilMouseUp:] + 0x3fc
26 com.apple.AppKit 0x92ec96cc -[NSButtonCell
trackMouse:inRect:ofView:untilMouseUp:] + 0x234
27 com.apple.AppKit 0x92e8e904 -[NSControl mouseDown:] + 0x208
28 com.apple.AppKit 0x92e02c60 -[NSWindow sendEvent:] + 0x10e4
29 com.apple.AppKit 0x92df5324 -[NSApplication sendEvent:] +
0xebc
30 com.apple.AppKit 0x92dfd73c -[NSApplication run] + 0x240
31 com.apple.AppKit 0x92eb9b80 NSApplicationMain + 0x1d0
32 main.ob 0x002faf74 main + 0x38 (main.m:13)
33 org.neurolens.neurolens 0x000026c8 start + 0x1c8
34 dyld 0x8fe1a558 _dyld_start + 0x64
_______________________________________________
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.