I have a SwiftUI Menu Bar App with no visible Windows on startup, except an entry in the Menu Bar with a Button showing a View on click.
This works great, but sporadically, the App throws an assertion and the MenuBar Button is not added, though its impossible to click it.
Here is what does not solve the issue:
- Cleaning Build + Derived Data
- Reboots
Code in AppDelegate (needed for the MenuBar)
@main // Assertion thrown here
struct MenuBarApp: App {
@Environment(\.scenePhase) var scenePhase
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
// This surpresses opening an empty Window on launch
ZStack{
EmptyView()
}.hidden() // removing .hidden() sometimes make the assertion go away, sometimes having .hidden() here triggers it
// Sometimes, a second ZStack makes the assertion dissappear, sometimes it triggers it.
}
}
}
The assertion reads:
2022-05-24 12:58:06.263464+0200 MenuBar[7119:96419] *** Assertion failure in void _NSWindowSetFrameIvar(NSWindow *, NSRect)(), NSWindow.m:935
2022-05-24 13:04:40.477258+0200 MenuBar[7119:96419] Invalid parameter not satisfying: <SwiftUI.SwiftUIWindow: 0x159e63780>. "frame=CGRectContainsRect(CGRectMake((CGFloat)INT_MIN, (CGFloat)INT_MIN, (CGFloat)INT_MAX - (CGFloat)INT_MIN, (CGFloat)INT_MAX - (CGFloat)INT_MIN), frame)"
On other machines the build and launch of the same Code runs perfectly fine.
func applicationDidFinishLaunching(_ notification: Notification)
is not getting called in the assert case
macOS 12.4, M1 Max, XCode 13.3.1