We got a segmentation fault on our Testflight build (not on debug builds). The build was created with the latest xCode version, the code is written in Swift (SwiftUI).
Luckily, one developer still uses an older version of xCode (12.4) and realised that the code doesn't compile for that version. We get a "Variable ... used before being initialized" compiler error.
Turns out that fixing the compiler error also fixes the segmentation fault crash.
@Binding var playingId: Int?
@State var player: AVPlayer
init(playingId: Binding<Int?>,) {
self.player = AVPlayer()
self._playingId = playingId
}
changed to:
@Binding var playingId: Int?
@State var player: AVPlayer = AVPlayer()
init(playingId: Binding<Int?>,) {
self._playingId = playingId
}
So, I wonder where the problem lies:
- Is this a compiler bug in the newest version?
- A runtime problem?
- Or a problem in the language definition?
The fact is that this does not initialise a State var
self.player = AVPlayer()
if you add a print just after, you'll see it
print("Just after init", self.player)
What is surprising and worth a bug report is the change in compiler behaviour between the Xcode releases. Please post the bug report reference and don't forget to close the thread.