Reputation: 81
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
Upvotes: 8
Views: 8470
Reputation: 942
I was getting this bug while using Core Audio. I was able to fix it by setting compiler optimization to "-O0 None."
Upvotes: 0