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

6

13

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

Findley answered 24/2, 2015 at 16:55 Comment(4)
Do you have exception breakpoints turned on? If you turn them off does the issue persist?Transitory
I have exception breakpoints turned offFindley
Which breakpoints do you have enabled?Transitory
I have deleted all breakpointsFindley
F
7

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

Findley answered 24/2, 2015 at 22:10 Comment(0)
C
18

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.

Coagulum answered 26/11, 2018 at 16:54 Comment(0)
P
16

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

Prospectus answered 28/1, 2016 at 6:47 Comment(2)
That's not the only possible reasonJadwigajae
He never said it was. It's a totally fair answer. And since the OP's problem did turn out to be a null object...Triserial
F
7

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

Findley answered 24/2, 2015 at 22:10 Comment(0)
C
2

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 !

Cyder answered 10/4, 2016 at 5:52 Comment(0)
T
0

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

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

Transitory answered 24/2, 2015 at 17:4 Comment(4)
Thanks for the answer, Aaron! Actually item.assetURL has type NSURL!, and explicitly unwrapping it with MediaAsset(url: item.assetURL!, type: .Audio) doesn't solved the problemFindley
And item itself is not optional (it has type MPMediaItem) and inserting your code gives an error "Bound value in conditional binding must be of Optional type".Findley
Sorry, I was thrown off by "Optional" in the log, but that's from absoluteString().Transitory
Yes, you are right, absoluteString() returns optionalFindley
J
0

In my case, I faced this issue due to DispatchSemaphore. DispatchSemaphore signal() was not called for a failure case which resulted in this crash.

Juliettajuliette answered 15/11, 2023 at 7:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.