Note that there are some explanatory texts on larger screens.

plurals
  1. PONSKeyedUnarchiver chokes when trying to unarchive more than one object
    primarykey
    data
    text
    <p>We've got a custom matrix class, and we're attempting to archive and unarchive an NSArray containing four of them. The first seems to get unarchived fine (we can see that initWithCoder is called once), but then the program simply hangs, using 100% CPU. It doesn't continue or output any errors. These are the relevant methods from the matrix class (rows, columns, and matrix are our only instance variables):</p> <p><pre><code> -(void)encodeWithCoder:(NSCoder*) coder { float temp[rows * columns]; for(int i = 0; i &lt; rows; i++) { for(int j = 0; j &lt; columns; j++) { temp[columns * i + j] = matrix[i][j]; }<br> }</p> <pre><code>[coder encodeBytes:(const void *)temp length:rows*columns*sizeof(float) forKey:@"matrix"]; [coder encodeInteger:rows forKey:@"rows"]; [coder encodeInteger:columns forKey:@"columns"]; </code></pre> <p>} </pre></code></p> <p><pre><code> -(id)initWithCoder:(NSCoder *) coder { if (self = [super init]) { rows = [coder decodeIntegerForKey:@"rows"]; columns = [coder decodeIntegerForKey:@"columns"]; NSUInteger * len; *len = (unsigned int)(rows * columns * sizeof(float)); float * temp = (float * )[coder decodeBytesForKey:@"matrix" returnedLength:len]; matrix = (float ** )calloc(rows, sizeof(float*)); for (int i = 0; i &lt; rows; i++) { matrix[i] = (float*)calloc(columns, sizeof(float)); } for(int i = 0; i &lt; rows *columns; i++) { matrix[i / columns][i % columns] = temp[i]; } } return self; } </pre></code></p> <p>And this is really all we're trying to do:</p> <p><pre><code> NSArray * weightMatrices = [NSArray arrayWithObjects:w1,w2,w3,w4,nil]; [NSKeyedArchiver archiveRootObject:weightMatrices toFile:@"weights.archive"]; NSArray * newWeights = [NSKeyedUnarchiver unarchiveObjectWithFile:@"weights.archive"]; </pre></code></p> <p>We've tried archiving one at a time (no NSArray), each to a different file, but it still hangs on the second one.</p> <p>What's driving us crazy is that we can archive and unarchive a single matrix just fine. We've done so (successfully) with a matrix many times larger than these four combined.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload