0

I'm targeting iOS 16 for a project and found that changing an SF Symbol Image's .symbolRenderingMode with an .animation applied sometimes causes a EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) crash with no meaningful stack trace or debug output. Removing .animation or keeping the .symbolRenderingMode constant prevents crashes. The exception points to the @main decorator of the main app file and this is the only stack trace provided:

stack trace showing the app's main entry point

And this is the tail of the assembly code pointed by the topmost symbol in the stack trace: enter image description here

Am I doing something wrong here or is this an SDK bug? I'd like to have the ability to transition between modes, but I'd be okay settling for only .multicolor if I have to - just can't figure out why this is happening in the first place. Below is my minimum reproducible example:

import SwiftUI

struct ContentView: View {
    @State var mode = 0
    var modeName: String {
        mode == 0 ? "Palette" : mode == 1 ? "Multicolor" : "Monochrome"
    }
    var nextModeName: String {
        mode == 0 ? "Multicolor" : mode == 1 ? "Monochrome" : "Palette"
    }

    var body: some View {
        VStack {
            Image(systemName: "list.bullet.clipboard")
                .font(.system(size: 50))
                .symbolRenderingMode(mode == 0 ? .palette : mode == 1 ? .multicolor : .monochrome)
                .foregroundStyle(.primary, .secondary)
                .padding()
        
            Text("Current SRM: \(modeName)")
            Button("Tap to set SRM to: \(nextModeName)", action: {mode = mode == 2 ? 0 : mode + 1})
        }
        // Commenting out this line stops crashes
        .animation(.linear, value: mode)
    }
}
Greg Whatley
  • 1,020
  • 1
  • 13
  • 32

1 Answers1

0

It seems like a bug...

I recreated the project using an enum and I was getting the same crash.

After changing the position of monochrome a couple of times I could not reproduce it.

import SwiftUI

@available(iOS 15.0, *)
struct RenderSampleView: View {
    @State var mode: RenderSamples = .palette
    
    var next: RenderSamples{
        RenderSamples(rawValue: mode == RenderSamples.allCases.last ? 0 : mode.rawValue + 1)!
    }
    
    var body: some View {
        VStack {
            Image(systemName: "list.bullet.clipboard")
                .font(.system(size: 50))
                .symbolRenderingMode(mode.mode)
                .foregroundStyle(.primary, .secondary)
                .padding()
            
            Text("Current SRM: \(mode.name)")
            Button("Tap to set SRM to: \(next.name)", action: {
                mode = next
            })
        }
        // Commenting out this line stops crashes
        .animation(.linear, value: mode)
    }
}
@available(iOS 15.0, *)
enum RenderSamples: Int, CaseIterable{
    case palette
    case monochrome // Alternate
    case multicolor
    //case monochrome //Alternate
    var name: String{
        switch self{
        case .palette:
            return "Palette"
        case .multicolor:
            return "Multicolor"
        case .monochrome:
            return "Monochrome"
        }
    }
    var mode: SymbolRenderingMode{
        switch self{
        case .palette:
            return .palette
        case .multicolor:
            return .multicolor
        case .monochrome:
            return .monochrome
        }
    }
    
}



@available(iOS 15.0, *)
struct RenderSampleView_Previews: PreviewProvider {
    static var previews: some View {
        RenderSampleView()
    }
}
lorem ipsum
  • 21,175
  • 5
  • 24
  • 48