Nikita Arkhipov Nikita Arkhipov - 1 year ago 123
Swift Question

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

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.

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("item: \(item), url: \(item.assetURL.absoluteString)")
delegate?.songPickerViewController(self, didPickedAsset: MediaAsset(url: item.assetURL, type: .Audio))

It actually generates output to console:

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

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

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

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?

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

Answer Source

I found an answer. Error was in self.asset.videoTrack!.nominalFrameRate, because in case of an audio asset.videoTrack will 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 swift related bugs

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download