Re: crashes loading saved file
Re: crashes loading saved file
- Subject: Re: crashes loading saved file
- From: James Maxwell <email@hidden>
- Date: Mon, 28 May 2012 22:08:38 -0700
>
> I think I was referring to that inner voice that *tempts* you to blame, not any actual blaming. :)
Sure, understood.
>
> We're probably at the point where you need to start showing code, at least in a reduced version, for encodeWithCoder and initWithCoder.
>
- (void) encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:eventKey forKey:@"eventKey"];
[aCoder encodeObject:value forKey:@"value"];
[aCoder encodeInt:type forKey:@"type"];
[aCoder encodeInt:state forKey:@"state"];
[aCoder encodeFloat:closure forKey:@"closure"];
[aCoder encodeInt:depth forKey:@"depth"];
[aCoder encodeInt:count forKey:@"count"];
[aCoder encodeFloat:probability forKey:@"probability"];
[aCoder encodeObject:schemaNode forKey:@"schemaNode"];
[aCoder encodeObject:parentNodes forKey:@"parentNodes"];
[aCoder encodeObject:childNodes forKey:@"childNodes"];
[aCoder encodeObject:targetNodes forKey:@"targetNodes"];
[aCoder encodeObject:targetEdgeCounts forKey:@"targetEdgeCounts"];
[aCoder encodeObject:sourceNodes forKey:@"sourceNodes"];
[aCoder encodeObject:superState forKey:@"superState"];
[aCoder encodeObject:subStates forKey:@"subStates"];
}
- (id) initWithCoder:(NSCoder *)aDecoder
{
if((self = [super init]))
{
eventKey = [[aDecoder decodeObjectForKey:@"eventKey"] retain];
value = [[aDecoder decodeObjectForKey:@"value"] retain];
type = [aDecoder decodeIntForKey:@"type"];
state = [aDecoder decodeIntForKey:@"state"];
closure = [aDecoder decodeFloatForKey:@"closure"];
depth = [aDecoder decodeIntForKey:@"depth"];
count = [aDecoder decodeIntForKey:@"count"];
probability = [aDecoder decodeFloatForKey:@"probability"];
schemaNode = [[aDecoder decodeObjectForKey:@"schemaNode"] retain];
parentNodes = [[aDecoder decodeObjectForKey:@"parentNodes"] retain];
childNodes = [[aDecoder decodeObjectForKey:@"childNodes"] retain];
targetNodes = [[aDecoder decodeObjectForKey:@"targetNodes"] retain];
targetEdgeCounts = [[aDecoder decodeObjectForKey:@"targetEdgeCounts"] retain];
sourceNodes = [[aDecoder decodeObjectForKey:@"sourceNodes"] retain];
superState = [[aDecoder decodeObjectForKey:@"superState"] retain];
subStates = [[aDecoder decodeObjectForKey:@"subStates"] retain];
}
return self;
}
CbCMNode is a NSObject subclass, btw.
> Incidentally, assuming each CbCMNode instance has a child array and a parent pointer, you aren't trying to to archive both, are you? I wouldn't expect that to work.
Well, yes, that's what happens. In fact, it's much hairier than that! There's actually an array of parentNodes, not just one. It's a complex graph, as I mentioned, not a straightforward tree (which would already contain mutual parent/child references, it seems to me). In my structure, there are about three dimensions of this kind of referencing, allowing me to move around the graph in useful ways… It's encoding hierarchical musical structure, for a music learning/generation algorithm, so there's a lot of complexity involved. As I say, it loads fine with smaller files, and testing the structure after loading indicates that it has been reconstructed properly. This is why I suspect there's a problem with trying to keep track of all these relationships during unarchiving, which NSKeyedUnarchiver does on the stack, afaik. There's an interesting discussion on this here:
http://forum.soft32.com/mac/Archiving-large-graphs-part-II-ftopict44343.html
It's a very old thread, from 2004, but it does seem to be addressing similar problems. And I think these cases are rare enough that Apple wouldn't necessarily put a bunch of time into improving them… besides, Michael Ash's comments seem to suggest that they really couldn't improve matters anyway, within the overall design of the NSCoder model. I just wondered if, perhaps, there was a way to get the whole thing to happen on the heap, rather than the stack, so that it could complete successfully. It would be slow, but I could deal with that for the time being (i.e., until I get my doctorate finished, after which time I could rip it apart and try a different approach!).
I did try, btw, using encodeConditionalObject for parentNodes, sourceNodes, and superState, all of which are CbCMNodes. But the structure was no longer intact after trying this (parent connections gone), so I think I misunderstood how conditional objects are supposed to work...
J.
James B Maxwell
Composer/Doctoral Candidate
School for the Contemporary Arts (SCA)
School for Interactive Arts + Technology (SIAT)
Simon Fraser University
_______________________________________________
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