【问题标题】:App is crashing on iPad 3 but not on iPad 2 - Crash Log应用程序在 iPad 3 上崩溃,但在 iPad 2 上没有 - 崩溃日志
【发布时间】:2012-05-10 16:39:44
【问题描述】:

我有一个应用程序在 iPad2 上运行良好,但由于在 iPad 3 上崩溃而被 Apple 拒绝。

我已经对崩溃日志进行了符号化,并将崩溃范围缩小到以下方法。

-(void)mergeTwoVideos {

//AVExport (oddly) has a problem with file name already existing - therefore check if file already exists and delete if needed.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:@"FinishedVideo.mov"];

if([fileManager fileExistsAtPath:writablePath]){ 
    NSLog(@"Problem - file already exists");
    [fileManager removeItemAtPath:writablePath error:NULL];
}
else{ 
    NSLog(@"No Problem - New File");
}

//Instantiate AVMutable Composition.

CMTime nextClipStartTime = kCMTimeZero;

AVURLAsset* a_videoAsset = [AVURLAsset URLAssetWithURL: [assetURLArray objectForKey:kIntroVideo] options:nil];

AVMutableComposition* mixComposition = [AVMutableComposition composition];

CMTimeRange a_timeRange = CMTimeRangeMake(kCMTimeZero,a_videoAsset.duration);
AVMutableCompositionTrack *a_compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];


[a_compositionVideoTrack insertTimeRange:a_timeRange ofTrack:[[a_videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:nextClipStartTime error:nil];

nextClipStartTime = CMTimeAdd(nextClipStartTime, a_timeRange.duration);

AVURLAsset* b_videoAsset = [AVURLAsset URLAssetWithURL: [assetURLArray objectForKey:kMainVideo] options:nil];

CMTimeRange b_timeRange = CMTimeRangeMake(kCMTimeZero, b_videoAsset.duration);
[a_compositionVideoTrack insertTimeRange:b_timeRange ofTrack:[[b_videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:nextClipStartTime error:nil];
[compositionAudioTrack insertTimeRange:b_timeRange ofTrack:[[b_videoAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:nextClipStartTime error:nil];

nextClipStartTime = CMTimeAdd(nextClipStartTime, b_videoAsset.duration);

AVURLAsset* c_videoAsset = [AVURLAsset URLAssetWithURL: [assetURLArray objectForKey:kIntroVideo] options:nil];
CMTimeRange c_timeRange = CMTimeRangeMake(kCMTimeZero, c_videoAsset.duration);
[a_compositionVideoTrack insertTimeRange:c_timeRange ofTrack:[[c_videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:nextClipStartTime error:nil];

AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetMediumQuality];

NSString *exportVideoPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/FinishedVideo.mov"];

NSURL *exportURL = [NSURL fileURLWithPath:exportVideoPath];
exportSession.outputURL = exportURL;
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;

[exportSession exportAsynchronouslyWithCompletionHandler:^{
    switch (exportSession.status) {
        case AVAssetExportSessionStatusFailed:{
            NSLog (@"FAIL");
            break;
        }
        case AVAssetExportSessionStatusCompleted: {
            NSLog (@"SUCCESS");
            [exportSession release];
            [self finishMergingProcess];
}
};
 }];

}

符号化的崩溃日志如下:

Thread 4 name:  Dispatch queue: com.apple.root.default-priority
Thread 4 Crashed:
0   libsystem_kernel.dylib          0x36d4832c __pthread_kill + 8
1   libsystem_c.dylib               0x3173a208 pthread_kill + 48
2   libsystem_c.dylib               0x31733298 abort + 88
3   libc++abi.dylib                 0x36c10f64 abort_message + 40
4   libc++abi.dylib                 0x36c0e346 _ZL17default_terminatev + 18
5   libobjc.A.dylib                 0x3682b350 _objc_terminate + 140
6   libc++abi.dylib                 0x36c0e3be _ZL19safe_handler_callerPFvvE + 70
7   libc++abi.dylib                 0x36c0e44a std::terminate() + 14
8   libc++abi.dylib                 0x36c0f798 __cxa_throw + 116
9   libobjc.A.dylib                 0x3682b290 objc_exception_throw + 88
10  CoreFoundation                  0x31f1f9d4 -[__NSArrayM objectAtIndex:] + 264
11  AppName                         0x00023d6e -[ViewController mergeTwoVideos]     (ViewController.m:746)
12  libdispatch.dylib               0x31eb4c52 _dispatch_call_block_and_release + 6
13  libdispatch.dylib               0x31eb7810 _dispatch_worker_thread2 + 252
14  libsystem_c.dylib               0x316f5df4 _pthread_wqthread + 288
15  libsystem_c.dylib               0x316f5cc8 start_wqthread + 0

谁能提供有关导致 iPad 3 崩溃的原因的任何见解?令人沮丧的是我没有 iPad3 来测试自己,所以感谢任何帮助。

谢谢!

【问题讨论】:

  • 第 746 行是哪一行?是否提供了任何崩溃消息?
  • [a_compositionVideoTrack insertTimeRange:a_timeRange ofTrack:[[a_videoAsset trackingWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:nextClipStartTime error:nil];
  • 崩溃消息是异常类型:EXC_CRASH (SIGABRT)

标签: objective-c xcode ipad crash


【解决方案1】:

您正试图通过索引从 NSArray 中抓取一个对象,其中该数组没有该数量的元素。

考虑到objectAtIndex:0 的调用次数,您没有首先检查数组是空还是 nil,因此其中任何一个都可能是问题所在。

考虑到您在代码中没有验证以确保 URL 正确、正在加载资产或预期的零碎资产,该代码中有许多潜在的故障点。

您需要修改代码以自始至终进行防御;检查 nil,检查空数组,检查加载 URL 失败等...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多