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:
And this is the tail of the assembly code pointed by the topmost symbol in the stack trace:
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)
}
}