Post

Replies

Boosts

Views

Activity

Freeze when deallocating large data structures
Hi everyone, I have encountered a strange Swift runtime crash/freeze when large data structures created from recursive enums with associated values are automatically deallocated. I am unable to debug this issue and I was wondering if anyone has some advice on what to do here? Here's my code: enum MyList {   case empty   indirect case pair(MyList, MyList) } var lst = MyList.empty for _ in 0..<150000 {   lst = .pair(.empty, lst) } print("Done creating list") lst = .empty print("Completed program (this is never printed)") This code uses an enum to represent a simple linear list. The loop creates 150,000 linearly linked nodes and ultimately prints "Done creating list". The following statement (which implicitly deallocates the long list) never returns. This is where I am stuck. It seems to be impossible to deallocate such a data structure without the Swift runtime freezing. Any help is appreciated! == Matthias
3
0
950
Nov ’21
SwiftUI 4 navigation bug on iOS 16?
Hi everyone, I am running into a navigation-related issue that appears to be new in iOS 16/SwiftUI 4. The code below illustrates the problem: struct ContentView: View {   @State private var input: String = ""   var body: some View {     NavigationStack {       VStack {         Spacer()         NavigationLink("Navigate") {           Text("Nested View")         }         Spacer()         TextEditor(text: $input)           .border(.red)           .frame(height: 40)       }       .padding()     }   } } The initial view consists of a navigation link and a text editor at the bottom of the screen. I run the app on an iPhone (or the simulator) in iOS 16 and click on the text editor at the bottom of the screen. This invokes the virtual keyboard, which pushes up the text field. Next, I click on "Navigate" to navigate to the nested view. I navigate immediately back, which brings back the initial view without the keyboard. Unfortunately, the text field isn't pushed back to the bottom and is now located in the middle of the screen. (see attached image) Did anyone experience similar issues? Is there a workaround I could use to force a re-layout of the initial view upon return from the navigation link? Thanks, Matthias
8
2
3.1k
Sep ’22
Threads with classic lock-based synchronization in SwiftUI in Xcode 16
Hi, I am stuck moving one of my projects from Xcode 15 to Xcode 16. This is a SwiftUI application that uses in some places classic Threads and locks/conditions for synchronization. I was hoping that in Swift 5 mode, I could compile and run this app also with Xcode 16 so that I can start migrating it towards Swift 6. Unfortunately, my application crashes via EXC_BREAKPOINT (code=1, subcode=0x1800eb31c) whenever some blocking operation e.g. condition.wait() or DispatchQueue.main.sync { ... } is invoked from within the same module (I haven't seen this happening for frameworks that use the same code that I linked in dynamically). I have copied an abstraction below that I am using, to give an example of the kind of code I am talking about. I have verified that Swift 5 is used, "strict concurrency checking" is set to "minimal", etc. I have not found a workaround and thus, I'm curious to hear if others were facing similar challenges? Any hints on how to proceed are welcome. Thanks, Matthias Example abstraction that is used in my app. It's needed because I have synchronous computations that require a large stack. It's crashing whenever condition.wait() is executed. public final class TaskSerializer: Thread { /// Condition to synchronize access to `tasks`. private let condition = NSCondition() /// The tasks queue. private var tasks = [() -> Void]() public init(stackSize: Int = 8_388_608, qos: QualityOfService = .userInitiated) { super.init() self.stackSize = stackSize self.qualityOfService = qos } /// Don't call directly; this is the main method of the serializer thread. public override func main() { super.main() while !self.isCancelled { self.condition.lock() while self.tasks.isEmpty { if self.isCancelled { self.condition.unlock() return } self.condition.wait() } let task = self.tasks.removeFirst() self.condition.unlock() task() } self.condition.lock() self.tasks.removeAll() self.condition.unlock() } /// Schedule a task in this serializer thread. public func schedule(task: @escaping () -> Void) { self.condition.lock() self.tasks.append(task) self.condition.signal() self.condition.unlock() } }
0
0
64
1d