mach_vm_map(size=) failed (error code=3)

荒凉一梦 提交于 2019-12-06 00:50:16

问题


I am trying to save video from album to my document directory. It's working fine for videos less than 1 minute. But when I am trying to save videos more than 1 minute, my app is getting crashed. This is happening only in iPhone, in iPad it's working working for larger videos as well.

This is my code :

    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];

My app is getting crashed at :

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

Error :

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

回答1:


I was getting this bug while using Core Audio. I was able to fix it by setting compiler optimization to "-O0 None."



来源:https://stackoverflow.com/questions/24504819/mach-vm-mapsize-failed-error-code-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!