Last active
October 18, 2024 17:10
-
-
Save ryanlintott/7ad53982a54a850bbdc03d4b37f493a2 to your computer and use it in GitHub Desktop.
FB15126597: AlignmentGuide crash when animating a Shape property. If an alignmentGuide affects the layout of a Shape with an animated property, changes to that property cause the app to crash. This crash occurs in Xcode 16 RC1 only when running in Swift 6 language mode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CrashingView: View { | |
@State private var items: [String] = Array(1...10).map { String("\($0)") } | |
var body: some View { | |
VStack { | |
HStack { | |
ForEach(items, id: \.self) { item in | |
Text(item) | |
/// Adding @Sendable to the closure fixes the crash | |
.alignmentGuide(HorizontalAlignment.center) { @Sendable d in | |
d[HorizontalAlignment.center] | |
} | |
} | |
} | |
/// Comment out the animation and removing an item will not crash the app. | |
.animation(.default, value: items) | |
HStack { | |
/// Tap this button to remove an item and crash the app | |
/// It will also log the following | |
/// `void * _Nullable NSMapGet(NSMapTable * _Nonnull, const void * _Nullable): map table argument is NULL` | |
Button("Remove Item") { | |
removeLastItem() | |
} | |
.padding() | |
} | |
.padding() | |
} | |
} | |
func removeLastItem() { | |
if !items.isEmpty { | |
items.removeLast() | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct CrashingView2: View { | |
@State private var radius: CGFloat = 10 | |
var body: some View { | |
VStack { | |
Color.blue | |
/// Remove @Sendable from this closure to see the crash | |
.alignmentGuide(.bottom) { @Sendable d in | |
0 | |
} | |
.background(alignment: .bottom) { | |
RoundedRectangle(cornerRadius: radius) | |
} | |
/// Change the radius and the view will crash | |
Stepper("Radius", value: $radius, in: 0...100, step: 5) | |
} | |
/// Comment out the animation and changes to the radius will not crash the app. | |
.animation(.default, value: radius) | |
.padding() | |
} | |
} | |
#Preview { | |
CrashingView2() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update: Add @.Sendable to the alignmentGuide closures to prevent the crash! Thanks to @mattmassicotte for this fix.