Skip to content

Fix crash from unchecked windowNumber -> CGWindowID conversion - #989

Open
Leunammih wants to merge 4 commits into
jordanbaird:mainfrom
Leunammih:fix/windowid-overflow-crash
Open

Leunammih wants to merge 4 commits into
jordanbaird:mainfrom
Leunammih:fix/windowid-overflow-crash

Conversation

@Leunammih

Copy link
Copy Markdown

Summary

Both ControlItem.windowID and the frame-change handler in IceBarPanel convert
NSWindow.windowNumber to CGWindowID with the non-failable initializer:

CGWindowID(window.windowNumber)

windowNumber is Int, CGWindowID is UInt32, and this initializer traps on
overflow rather than returning nil. On macOS 26, windowNumber can return a value
outside UInt32's range for menu bar item windows (reported in #580 as consistently
greater than UInt32.max), which crashes the app with EXC_BREAKPOINT/SIGTRAP
matching the stack traces in #977 and other recent crash reports, and one I hit
myself on 0.11.12.

This swaps both call sites to the failable CGWindowID(exactly:), so an
out-of-range value degrades to nil (the existing optional-chaining call sites
already handle that gracefully) instead of crashing the process.

  • Ice/MenuBar/ControlItem/ControlItem.swiftwindowID getter
  • Ice/UI/IceBar/IceBar.swift — the control item's frame-change publisher, used to
    detect when the menu bar is hidden by the system

Testing

  • Builds clean (Debug, Xcode 26.6).
  • Ran the built app for ~27 hours of normal use with no crash and no new entries in
    ~/Library/Logs/DiagnosticReports/, versus multiple same-day crashes on 0.11.12
    before this change.

Fixes #977. Likely related to #580, #786, #867 (macOS 26 crashes around showing
hidden items / the Ice Bar).

🤖 Generated with Claude Code

Immanuel Holtmannspoetter and others added 4 commits September 8, 2026 11:01
CGWindowID(window.windowNumber) traps on overflow when windowNumber
is out of UInt32 range, which happens for menu bar item windows on
macOS 26 (see jordanbaird#580, jordanbaird#977 upstream). Switch both call
sites to the failable CGWindowID(exactly:) initializer so an
out-of-range value degrades to nil instead of crashing the app.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
WindowInfo(windowID:) is itself failable, so mapping into it with
.map produced a nested Optional (WindowInfo??) instead of flattening,
which failed to typecheck. Also ignore local .build/ derived data.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ream

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
It's a personal workspace tracking file, not meant to be part of the
upstream PR diff — kept on main in the fork instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: crashes whenever I use the trigger button in the menu bar

1 participant