Horrible weird Window Server killing bug

OS 26.s, Xcode 26.2

TLDR: My pure SwiftUI app freezes the window server, is this a known problem?

My app is pure SwiftUI, no low level calls, no networking, no tricksy pointer use. Somehow, something in my code is terminally confusing the Window Server. As in, I run the app, and before I ever seen a window, the Window Server locks up, and is killed by the OS for being unresponsive.

Using debugging shows that I get to the end of a Canvas, and it simply freezes upon exiting.

I'm about to do the old comment out everything, and bring it back a bit at a time, but I'm wondering if anyone is experiencing this sort of thing? The reaction is so extreme.

And it's not Xcode in particular, I built the program with xcodebuild, Xcode itself not running, and ran my app, and it did the same thing.

Urgh, I think it's a divide by zero bug.

So this can apparently crash the Window server:

Path { path in
        path.move(to: pt(qdt.qx * -20, 0))
        // DIV BY ZERO
        path.addLine(to: pt(qdt.qx * -20, qdt.qy * (sH)/cos(angle.radians)))
      }

If cos(angle.radians) is 0, you get a simple but unrecoverable divide by zero error, and hey, that's on me. But I would expect the system to kick my program with a nice "EDIVBYZERO", not take out the window server.

My solution to this is this function, which works because I don't need perfect accuracy:

func cosNZ(_ input: Double) -> Double {
  let x = cos(input)
  if x == 0.0 { return Double.leastNonzeroMagnitude }
  return x
}

This got even weirder. One is that sometimes the use of cos() would cause a compiler error, which was fixed by using Darwin.cos(). This may be fixed in Swift 6.3.

The other thing is that in my much more complex code, the crash seemed to be caused by both the cos() call evaluating to 0, but only when the line being drawn with that result had a StrokeStyle applied to it.

In anycase, I have filed Feedbacks explaining this, and I'm told the WindowServer team has had it brought to their attention.

Horrible weird Window Server killing bug
 
 
Q