Skip to content

fix: guard against nil CGDisplayCreateUUIDFromDisplayID in detectFullscreenDisplays#30

Merged
typester merged 1 commit intomainfrom
fix/crash-when-display-disconnected2
May 7, 2026
Merged

fix: guard against nil CGDisplayCreateUUIDFromDisplayID in detectFullscreenDisplays#30
typester merged 1 commit intomainfrom
fix/crash-when-display-disconnected2

Conversation

@typester
Copy link
Copy Markdown
Owner

@typester typester commented May 7, 2026

CGDisplayCreateUUIDFromDisplayID is imported as Unmanaged! (IUO) in
Swift because the C header has no nullability annotation. It returns NULL for
display ID 0 (kCGNullDirectDisplay), which the NSScreen.displayID extension
can produce as a fallback during display state transitions.

Calling .takeRetainedValue() on the nil IUO crashes with "Unexpectedly found
nil while implicitly unwrapping an Optional value". The previous fix guarded
CFUUIDCreateString instead, which was one line too late.

Add guard for displayID != 0 and guard let on the IUO return value so
invalid displays are skipped cleanly.

…screenDisplays

CGDisplayCreateUUIDFromDisplayID is imported as Unmanaged<CFUUID>! (IUO) in
Swift because the C header has no nullability annotation. It returns NULL for
display ID 0 (kCGNullDirectDisplay), which the NSScreen.displayID extension
can produce as a fallback during display state transitions.

Calling .takeRetainedValue() on the nil IUO crashes with "Unexpectedly found
nil while implicitly unwrapping an Optional value". The previous fix guarded
CFUUIDCreateString instead, which was one line too late.

Add guard for displayID != 0 and guard let on the IUO return value so
invalid displays are skipped cleanly.
@typester typester force-pushed the fix/crash-when-display-disconnected2 branch from f15bd25 to 3e2b4ee Compare May 7, 2026 20:49
@typester typester merged commit 64255b1 into main May 7, 2026
2 checks passed
@typester typester deleted the fix/crash-when-display-disconnected2 branch May 7, 2026 20:50
typester pushed a commit that referenced this pull request May 7, 2026
🤖 I have created a release *beep* *boop*
---


## [0.1.13](v0.1.12...v0.1.13)
(2026-05-07)


### Bug Fixes

* guard against nil CGDisplayCreateUUIDFromDisplayID in
detectFullscreenDisplays
([#30](#30))
([64255b1](64255b1))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.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.

1 participant