Hi All,
I updated to Xcode 12.1 today and encountered some unexpected behavior with Metal & curved paths in my app.
It took me a few hours to track down the source of this issue, so wanted to share in case anyone else has encountered this problem or has suggestions.
Notes:
I updated to Xcode 12.1 today and encountered some unexpected behavior with Metal & curved paths in my app.
It took me a few hours to track down the source of this issue, so wanted to share in case anyone else has encountered this problem or has suggestions.
Problem
Applying .drawingGroup() to a View containing a bezier curve (e.g., path.addCurve() or path.addQuadCurve()) causes the app to crash immediately, with only cryptic output in the console.Notes:
doesn't happen when drawing straight lines (path.addLine()), only curves
appears to be limited to the Simulators, as the crash doesn't occur on my iPhone XR / iOS 14.1
removing .drawingGroup() stops app from crashing
problem did not occur when using Xcode 12.0
Example Code
Code Block language import SwiftUI @main struct TestApp: App { var body: some Scene { WindowGroup { TestView() } } } struct TestView: View { @State private var redFill: Bool = true var body: some View { TestPath() .fill(redFill ? Color.red : Color.blue) // Drawing group here causes app to crash .drawingGroup() Button(action: { redFill.toggle() }) { Text("Change Color") } } } struct TestPath: Shape { func path(in rect: CGRect) -> Path { let width: CGFloat = rect.size.width let height: CGFloat = rect.size.height let pathWidth: CGFloat = 200 let startPoint = CGPoint( x: 0.5*(width - pathWidth), y: 0.5*(height) ) let endPoint = CGPoint( x: 0.5*(width + pathWidth), y: 0.5*(height) ) let control1 = CGPoint( x: 0.5*(width), y: 0.5*(height + pathWidth) ) let control2 = CGPoint( x: 0.5*(width), y: 0.5*(height - pathWidth) ) let path = Path { path in path.move(to: startPoint) path.addCurve( to: endPoint, control1: control1, control2: control2 ) path.closeSubpath() } return path } }
Console Output
Code Block language ... Metal GPU Frame Capture Enabled ... Metal API Validation Enabled ... [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed ... Connection 1: received failure notification ... Connection 1: failed to connect 3:-9816, reason -1 ... Connection 1: encountered error(3:-9816) ... Task <...>.<1> HTTP load failed, 0/0 bytes (error code: -1200 [3:-9816]) ... [error] precondition failure: pipeline error: accumulator_color-13f4500040004f: Compiler encountered an internal error ... CoreSimulator 732.17 - Device: iPhone 11 (...) - Runtime: iOS 14.1 (18A8394) - DeviceType: iPhone 11 ... RenderBox precondition failure: pipeline error: accumulator_color-13f4500040004f: Compiler encountered an internal error.