New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-4971] Optional binding for URL struct (possible miscompile?) #47548
Comments
Comment by Jun Ma (JIRA) I have uploaded the project about how to reproduce the problem as attachment. |
Nothing jumps out at me here; we'll need to look into it further. Does this happen in both Debug and Release builds? @swift-ci create |
Comment by Jun Ma (JIRA) Yes,it happens in both Debug and Release builds. The attachment project will reproduce the problem. Look forward to your further research 😃 |
I reproduced this in Xcode 8.3.2. The error message that gets printed on the console pretty clearly shows the problem: fatal error: unexpectedly found nil while unwrapping an Optional value I set a breakpoint and confirmed that the closure is getting called with a nil value for audioUrl. I don't know what is causing that in your code, but you should not force-unwrap an Optional unless you are certain that it is non-nil. |
Jordan pointed out that the error I saw is different than what was reported here. If you can explain how to reproduce that other issue, I can try again. |
I think I saw that problem because I tested it on the simulator, not a real device. |
I still cannot reproduce the problem reported here. I switched to using a real iPhone instead of the simulator. On the first run, I get other errors which are apparently related to copying the video files. On subsequent runs, I get the same force-unwrap error. |
Comment by Jun Ma (JIRA) I have modified the demo project to reproduce the problem. |
Comment by Jun Ma (JIRA) I've updated the demo project. Here is steps on how to reproduce the problem: 1. build and run it will succeed to export a new audiovisual. 2. uncomment the commented statements in ViewController.swift and comment statements below them, it will looks like this: if let audio = audioUrl {
let reversedAudioAsset = AVURLAsset(url: audio)
reversedAudioAssetTrack = reversedAudioAsset.tracks(withMediaType: AVMediaTypeAudio).first
}
// let reversedAudioAsset = AVURLAsset(url: audioUrl!)
// reversedAudioAssetTrack = reversedAudioAsset.tracks(withMediaType: AVMediaTypeAudio).first
if let video = videoUrl {
let reversedVideoAsset = AVURLAsset(url: video)
reversedVideoAssetTrack = reversedVideoAsset.tracks(withMediaType: AVMediaTypeVideo).first
}
// let reversedVideoAsset = AVURLAsset(url: videoUrl!)
// reversedVideoAssetTrack = reversedVideoAsset.tracks(withMediaType: AVMediaTypeVideo).first 3. build and run, the error catched. |
This seems to be sensitive to timing. I can reproduce it now, but if I step through the code and stop and print variables along the way, then it works about half the time. Given that, it seems unlikely that this is a Swift bug. It might be better to file an bug report with Apple about AVFoundation. |
Comment by Jun Ma (JIRA) OK, I will file a bug to team AVFoundation. |
There isn't really a good resolution in JIRA for something like this. I'll go with "Done". If you post the radar number for the AVFoundation bug report here, I can try to keep an eye on it. |
Attachment: Download
Environment
Macbook Pro (Retina, 13-inch, Late 2013, 8GB memory, 2.4 GHz Intel Core i5) with macOS 10.12.4
iPhone 7 with iOS 10.3.1(14E304), 256GB
Xcode 8.3.2 (8E2002), Swift 3.1
Additional Detail from JIRA
md5: ce3856a7aeda0edfa106bd89766b56a4
Issue Description:
I've working on an app using AVFoundation, and one of the task is to separate the captured video into audio and video part, here is snippet of my code:
Here is the problem:
I've checked the separated audio file URL and confirmed that it does exist. So I wonder what's problem I did wrong or, what's the problem with optional binding?
The text was updated successfully, but these errors were encountered: