ios 打印 url 时的 Xcode EXC_BREAKPOINT (code=1, subcode=...)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28701688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 04:58:09  来源:igfitidea点击:

Xcode EXC_BREAKPOINT (code=1, subcode=...) when printing url

iosxcodeswiftmemory

提问by Nikita Arkhipov

I have a strange bug in my own program. I'm currently working on Video Editing app. I have a SongPicker view controller, which displays all the songs from the user's music app. When the user selects a song, a new object (MediaAsset) representing that song is created. It worked perfectly fine, when SongPicker was written in Swift, and MediaAsset in Objective-C. However I rewrited MediaAsset completely on Swift and now every time I'm trying to create new MediaAsset from SongPicker, Xcode throwes EXC_BREAKPOINT (code=1, subcode=...) and my app crushes.

我自己的程序中有一个奇怪的错误。我目前正在开发视频编辑应用程序。我有一个 SongPicker 视图控制器,它显示用户音乐应用程序中的所有歌曲。当用户选择一首歌曲时,会创建一个代表该歌曲的新对象 (MediaAsset)。当 SongPicker 用 Swift 编写,MediaAsset 用 Objective-C 编写时,它运行得非常好。但是,我完全在 Swift 上重写了 MediaAsset,现在每次我尝试从 SongPicker 创建新的 MediaAsset 时,Xcode 都会抛出 EXC_BREAKPOINT (code=1, subcode=...) 并且我的应用程序崩溃。

Here is the code, that is called when user selects song:

这是用户选择歌曲时调用的代码:

private let mediaItems = MPMediaQuery.songsQuery().items as [MPMediaItem]

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
   let item = filteredMediaItems[indexPath.row]
   println("didSelectRowAtIndexPath")
   println("item: \(item), url: \(item.assetURL.absoluteString)")
   delegate?.songPickerViewController(self, didPickedAsset: MediaAsset(url: item.assetURL, type: .Audio))
}

It actually generates output to console:

它实际上生成输出到控制台:

didSelectRowAtIndexPath
item: <MPConcreteMediaItem: 0x174648340> 2369259457983598523, url: Optional("ipod-library://item/item.mp3?id=2369259457983598523")

then it goes to MediaAsset constructor, which looks like this:

然后它转到 MediaAsset 构造函数,它看起来像这样:

init(url: NSURL, type: MediaAssetType){
  println("new MediaAsset with url \(url.absoluteString)")
  self.url = url
  self.asset = AVURLAsset(URL: url, options: [AVURLAssetPreferPreciseDurationAndTimingKey: true])
  self.timeRange = CMTimeRangeMake(kCMTimeZero, self.asset.duration)
  self.initialRate = CGFloat(max(self.asset.videoTrack!.nominalFrameRate / 30.0, 1.0))
  self.rate = self.initialRate
  self.type = type
}

it prints to console:

它打印到控制台:

new MediaAsset with url Optional("ipod-library://item/item.mp3?id=2369259457983598523")

And on this line it crushes: Crush screenshot

在这条线上,它粉碎了: Crush screenshot

The code that creates asset from AVURLAsset is exactly the same as it was in my old ObjectiveC class (where it worked perfectly well), so the problem shouldn't belong to AVFoundation. Does anybody knows what can be reason of that crush? And as more general question, in which cases "EXC_BREAKPOINT (code=1, ..." arises?

从 AVURLAsset 创建资产的代码与我在旧的 ObjectiveC 类中的代码完全相同(它工作得很好),所以问题不应该属于 AVFoundation。有谁知道什么是暗恋的原因?作为更一般的问题,在哪些情况下会出现“EXC_BREAKPOINT (code=1, ...”)?

EDITAfter deleting this println statement, my app still crushes but now shows this assembler code:Crush

编辑删除此 println 语句后,我的应用程序仍然崩溃,但现在显示此汇编代码:Crush

采纳答案by Nikita Arkhipov

I found an answer. Error was in self.asset.videoTrack!.nominalFrameRate, because in case of an audio asset.videoTrackwill be nil, that's why app crashes. Just don't know why it behaves so strangely, pointing an error at println()line. Must be one of tons of Xcode's swiftrelated bugs

我找到了答案。错误在 中self.asset.videoTrack!.nominalFrameRate,因为在audio asset.videoTrackwill 为零的情况下,这就是应用程序崩溃的原因。只是不知道为什么它的行为如此奇怪,println()在行中指出错误。必须是 Xcode 的大量swift相关错误之一

回答by K.K

This exception happens when the value being unwrapped by the '!' operator is nil. Fix the nil value and the code should work.

当值被 '!' 解包时会发生此异常。运算符为零。修复 nil 值,代码应该可以工作。

回答by danielhadar

This error might also be caused if you dispatch something on the main queue synchronously inside an asynchronous block, that happens to run on the main queue as well:

如果您在异步块内同步地在主队列上分派某些内容,也可能会导致此错误,这恰好也在主队列上运行:

dispatch_async(dispatch_get_main_queue(), ^{    // This might happen unintentionally.
  dispatch_sync(dispatch_get_main_queue(), ^{
    // Do stuff.
  });
});

In this case your code will run into a deadlock caused by the fact that the asynchronous block won't complete until the synchronous block will complete, and it won't start until the asynchronous block complete.

在这种情况下,您的代码将陷入死锁,因为异步块在同步块完成之前不会完成,并且在异步块完成之前它不会启动。

回答by Alzayed

I faced the same problem, i tried Shift+Cmd+K to clean the project and it fixed the problem, Although i don't know why that happened !

我遇到了同样的问题,我尝试 Shift+Cmd+K 来清理项目并解决了问题,虽然我不知道为什么会这样!

回答by Aaron Brager

You're passing in a NSURL?instead of an NSURL.

您传入的是 aNSURL?而不是NSURL

You may also need to unwrap assetURLdepending on the type of object in filteredMediaItems(assetURLmay be optional).

您可能还需要assetURL根据filteredMediaItems(assetURL可能是可选的) 中的对象类型进行解包。