fix: guard GhosttyNSView screen observers against stale delivery (mechanism 2, part 2) - #259
Merged
Merged
Conversation
…istration Ports the #258 stale-notification generation guard to GhosttyNSView's windowObserver/screenParametersObserver, the one sibling that didn't get it. removeObserver does not cancel a block already handed to the main queue, so a block enqueued against a torn-down registration batch could still fire after viewDidMoveToWindow re-registered for a new window — reaching the notification.object as? NSWindow downcast against freed state. Forensic match: 5/6 reland-gate minidumps traced to this exact mechanism. windowObserverGeneration bumps on teardown (viewDidMoveToWindow) and deinit; each closure captures its generation at registration and no-ops before doing any work if the instance has since moved on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Completes the stale-notification hardening from #258. Gate forensics on the re-land found the residual crasher: 5/6 new minidumps byte-identical to the mechanism-2 signature, and the only unguarded sibling of the fixed pattern is GhosttyNSView's windowObserver/screenParametersObserver — same queue:.main registration, re-registered on every viewDidMoveToWindow, no generation guard. The evidence pins it precisely: one fault address decodes to ASCII 'New Term' (window-title memory), and the handler's notification.object as? NSWindow downcast requires exactly the objc_retain-of-freed-object that is frame 0 in four dumps.
Ports the identical generation-guard pattern from GhosttySurfaceScrollView (#258): generation captured at registration, bumped on teardown/re-registration and deinit, checked before anything else in both closures — before the downcast that crashes.
Test plan