Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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("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:

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?

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

like image 810
Nikita Arkhipov Avatar asked Feb 24 '15 16:02

Nikita Arkhipov


4 Answers

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

like image 109
K.K Avatar answered Nov 14 '22 19:11

K.K


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

like image 20
Nikita Arkhipov Avatar answered Nov 14 '22 20:11

Nikita Arkhipov


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.

like image 10
danielhadar Avatar answered Nov 14 '22 18:11

danielhadar


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 !

like image 2
Abdulrazzaq Alzayed Avatar answered Nov 14 '22 18:11

Abdulrazzaq Alzayed