2014-07-01 22 views
7

Sto cercando di salvare i video dall'album nella directory dei miei documenti. Funziona bene per i video meno di 1 minuto. Ma quando cerco di salvare video per più di 1 minuto, la mia app si arresta in modo anomalo. Questo sta accadendo solo in iPhone, in iPad funziona anche per video più grandi.mach_vm_map (size =) non riuscito (codice errore = 3)

Questo è il mio codice:

else if([mediaType isEqualToString:ALAssetTypeVideo]) 
    { 
     ALAssetsLibrary *librarys = [[ALAssetsLibrary alloc] init]; 

     [librarys enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) 
     { 
      [group setAssetsFilter:[ALAssetsFilter allVideos]]; 

      if ([group numberOfAssets] > 0) 
      { 
       for (int j = 0; j < [group numberOfAssets]; j++) 
       { 
        [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:j] 
              options:0 
              usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) 
         { 
          if (alAsset) 
          { 
           ALAssetRepresentation *representation = [alAsset defaultRepresentation]; 
           NSURL *url = [representation url]; 

           if ([[dict objectForKey:@"UIImagePickerControllerReferenceURL"] isEqual:url]) 
           { 
            Byte *buffer = (Byte*)malloc((unsigned)[representation size]); 
            //NSUInteger buffered = [representation getBytes:buffer fromOffset:0.0 length:representation.size error:nil]; 
            //Byte *buffer = ((Byte*)representation.size); 
            //NSUInteger chunkSize = 100 * 1024; 
           // uint8_t *buffer = malloc(chunkSize * sizeof(uint64_t)); 

            NSUInteger buffered = [representation getBytes:buffer fromOffset:0.0 length:(NSUInteger)representation.size error:nil]; 
            NSData *videoCameraData = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES]; 
            NSString *savedImagePath = [docDirectory stringByAppendingPathComponent:str_Header]; 
            NSError *error; 
            [[NSFileManager defaultManager] createDirectoryAtPath:savedImagePath withIntermediateDirectories:NO attributes:nil error:&error]; 

La mia app è sempre caduto a:

NSUInteger buffered = [representation getBytes:buffer fromOffset:0.0 length:(NSUInteger)representation.size error:nil]; 

Errore:

malloc: *** mach_vm_map(size=310386688) failed (error code=3) 
*** error: can't allocate region 
*** set a breakpoint in malloc_error_break to debug 
+0

dal tuo post Direi che richiedi troppa memoria ... – Volker

+0

@Volker Esiste un allenamento per salvare questi video senza consumare così tanta memoria? – Gill

+0

dividere l'utilizzo della memoria ... o utilizzare un file di scambio ... un buffer circolare ... tutto ciò che riduce la dimensione della memoria allocata. – Volker

risposta

0

mi è stato sempre questo bug durante l'utilizzo di Core Audio. Sono stato in grado di risolverlo impostando l'ottimizzazione del compilatore su "-O0 None".

Problemi correlati