错误:执行被中断,原因:EXC_BAD_ACCESS(code = 1,address = 0x20)

时间:2018-02-02 17:13:54

标签: objective-c xcode xcode9 lldb

我正在尝试打印出CMTimeRange对象的AVAssetTrack属性。

首先,我尝试过:

(lldb) p videoTrack.timeRange
error: property 'timeRange' not found on object of type 'AVAssetTrack *'

即使它明确定义为:

@interface AVAssetTrack (AVAssetTrackTemporalProperties)

/* Indicates the timeRange of the track within the overall timeline of the asset;
a track with CMTIME_COMPARE_INLINE(timeRange.start, >, kCMTimeZero) will initially present an empty interval. */
@property (nonatomic, readonly) CMTimeRange timeRange;

无论如何,我已经尝试过消息传递而不是属性访问,然后我得到了这个:

(lldb) p [videoTrack timeRange]
error: no known method '-timeRange'; cast the message send to the method's return type

好的,我将它转换为正确的类型CMTimeRange,我得到了这个:

(lldb) p (CMTimeRange)[videoTrack timeRange]
error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x20).
The process has been returned to the state before expression evaluation.

有问题的videoTrack是有效的对象:

(lldb) po videoTrack
<AVAssetTrack: 0x1cc00f2f0, trackID = 1, mediaType = vide>

为什么我收到EXC_BAD_ACCESS错误?

1 个答案:

答案 0 :(得分:0)

根据AVAssetTrack的文档属性不一定立即可用,但在调用时或通过显式加载异步加载。我的猜测是,当您尝试访问它时,timeRange尚未加载,和/或调试器以某种方式干扰加载机制。

  

AVAssetTrack采用AVAsynchronousKeyValueLoading协议。您   可以使用协议的statusOfValueForKey:error:方法来确定   如果可以访问track属性而不阻止调用   线程。

如果可能的话,或者尝试在断点之前预先加载timeRange属性,或者在完成时放置NSLog()并打破它。

[videoTrack loadValuesAsynchronouslyForKeys:@[ @"timeRange" ] completionHandler:^{
    NSLog(@"timeRange: %@", videoTrack.timeRange.description);
}];

您也可以尝试从调试器中调用statusOfValueForKey:error:方法。