mach_vm_map(size =)失败(错误代码= 3)

时间:2014-07-01 07:34:46

标签: objective-c alassetslibrary

我正在尝试将视频从相册保存到我的文档目录中。它适用于不到1分钟的视频。但是当我试图保存视频超过1分钟时,我的应用程序正在崩溃。这种情况只发生在iPhone上,在iPad上它正在为更大的视频工作。

这是我的代码:

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

我的应用程序正在崩溃:

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

错误:

 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 个答案:

答案 0 :(得分:0)

使用Core Audio时我遇到了这个错误。我能够通过将编译器优化设置为“-O0无”来修复它。