0

I have this code:

struct MyPickerSelection: View {
    @State private var picker1selection = 1
    @State private var picker2selection = 1
    @State private var showPicker1 = false
    @State private var showPicker2 = false
    
    var body: some View {
        Form {
            Section(header: Text("section 1")) {
                HStack {
                    Text("selection \(picker1selection)")
                    Spacer()
                    Button(action: {
                        showPicker1.toggle()
                    }) {
                        Text("show picker 1")
                    }.foregroundColor(showPicker1 ? .red : .blue)
                }
                
                if showPicker1 {
                    Picker("choose", selection: $picker1selection) {
                        Text("value 0").tag(0)
                        Text("value 1").tag(1)
                        Text("value 2").tag(2)
                        Text("value 3").tag(3)
                        Text("value 4").tag(4)
                    }.pickerStyle(WheelPickerStyle()).compositingGroup().clipped(antialiased: true)
                }
            }
            
            Section(header: Text("section 2")) {
                HStack {
                    Text("selection \(picker2selection)")
                    Spacer()
                    Button(action: {
                        showPicker2.toggle()
                    }) {
                        Text("show picker 2")
                    }.foregroundColor(showPicker2 ? .red : .blue)
                }
                
                if showPicker2 {
                    Picker("choose", selection: $picker2selection) {
                        Text("value 0").tag(0)
                        Text("value 1").tag(1)
                        Text("value 2").tag(2)
                        Text("value 3").tag(3)
                        Text("value 4").tag(4)
                    }.pickerStyle(WheelPickerStyle()).compositingGroup().clipped(antialiased: true)
                }
            }
        }
    }
}

This can make a view where you can unfold two Picker to select values from 0 to 4, in my app this code is more complex but this reproduces the same error, when you try to select a value from the second Picker some times the app crashes for no reason, or vice versa, trying to select a value from Picker one makes the app crashes, or just unfold one or two Pickers and trying to scroll cause an app crash. This feel really random bug.

I'm not sure what's causing this behavior, in iOS 14 never happen, everything was fine, until today update to iOS 15.

The only error message i receive from Xcode is Thread 1: EXC_BAD_ACCESS (code=1, address=0x97157b0daa1403d8)

I think this is being caused by the use of two scrollable elements, but can't say if its true.

Any suggestion?

lcpr_phoenix
  • 373
  • 4
  • 15
  • your code works well for me, on macos 12.0.1, xcode 13.1(RC), target ios 15 and macCatalyst. Maybe there is some other code causing your crash. Do the typical routine of `Clean Build Folder` and delete `DerivedData` and re-launch Xcode. – workingdog support Ukraine Oct 20 '21 at 01:00
  • @workingdog did you try in iPhone iOS 15? Maybe this error only occur on mobile devices – lcpr_phoenix Oct 20 '21 at 15:04
  • yes, tried it on real devices, iPhone and iPad both with IOS-15. Spent a minute or two changing the values, and no crash so far. – workingdog support Ukraine Oct 20 '21 at 23:01
  • I am seeing the same issue, both in simulator and on device. – jbaraga Nov 03 '21 at 00:57
  • I was able to prevent the crash by adding `.id(UUID())` modifier to my List, but this created undesirable flickering when changing selection. Ultimately I changed the List to a LazyVStack in a ScrollView, and resolved the issue. – jbaraga Nov 04 '21 at 01:45

0 Answers0