Learn Courses My Dashboard

Application freezes while trying to close a window

Hey, I wrote a menu bar app (for macOS only obviously) that can summon a “normal” window. Whenever I try to close that window, it freezes and i get the beachball for the rest of my life. Only Xcode itself can stop that app then. XCode shows me the Error message “Thread 1: EXC_BAD_ACCESS (code=1, address=0x20)” on the line of code where I define “@main”. I’ve found similar error messages where the declaration is something with Memory. Unfortunately I am too new to understand these.
This part triggers the window launch:

struct MyNewWindowView: View {
    let id: String // add an id property
    var body: some View {
        Text("New window \(id)")
            .frame(maxWidth: .infinity, maxHeight: .infinity)

func openNewWindow(withID id: String) {
    let newWindowView = MyNewWindowView(id: id)
    let newWindow = NSWindow(
        contentRect: NSRect(x: 0, y: 0, width: 800, height: 600),
        styleMask: [.titled, .closable, .miniaturizable, .resizable],
        backing: .buffered,
        defer: false)
    newWindow.contentView = NSHostingView(rootView: newWindowView)

That’s how the breakpoint navigator looks:

Thank you in advance for your help. I really appreciate it. :slight_smile:

A bit of Googling showed this thread. Maybe it will point you in the right direction.