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

问题描述 投票:7回答:1

我正在尝试将视频从相册保存到我的文档目录。不到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
objective-c alassetslibrary
1个回答
0
投票

我在使用Core Audio时遇到此错误。我可以通过将编译器优化设置为“ -O0 None”来修复它。

© www.soinside.com 2019 - 2024. All rights reserved.