gpui_macos: Guard deferred AppKit calls against closed windows (#51992)

MacWindow methods like activate(), zoom(), toggle_fullscreen(),
resize(), prompt(), and titlebar_double_click() capture the raw
native_window pointer and spawn detached async tasks on the foreground
executor. If the window is closed between the spawn and execution (e.g.
the user clicks the close button), the task sends AppKit messages to a
closed NSWindow, which throws an ObjC exception in
_changeKeyAndMainLimitedOK: and aborts the process.

Add an isVisible check inside each deferred task before sending messages
to the native window. After [NSWindow close], isVisible returns NO, so
the guard prevents the crash. Both the check and the subsequent AppKit
call execute synchronously within the same main-thread task, so there is
no TOCTOU race.

For prompt(), the else branch releases the alert object to avoid leaking
it; the oneshot sender inside the completion block is dropped, which
cancels the channel and propagates as an error to the caller.

Closes ZED-5TN


Release Notes:

- N/A or Added/Fixed/Improved ...
466995cb81Lukas Wirth committed on 3/23/2026, 4:29:32 PM· committed by GitHubparentf1f21d8
1 file changedLine totals unavailable