Repository navigation
Conversation
RXNova
force-pushed
the
fix/macos-kvo-subclass-teardown
branch
3 times, most recently
from
October 11, 2026 23:26
f4eeeaa to
1b5351e
Compare
Dropping the subclassing adapter while a key-value observer is registered on the view discarded KVO's dynamic subclass, so removing the observer later raised NSRangeException. AppKit registers such observers itself on the first responder, which made apps crash when closing a window.
RXNova
force-pushed
the
fix/macos-kvo-subclass-teardown
branch
from
October 11, 2026 23:32
1b5351e to
3740c92
Compare
This branch has not been deployed
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.
Closes #823
SubclassingAdapter::dropresets the view's class unconditionally. If a key-value observer was registered on the view after the adapter was created, this discards KVO'sNSKVONotifying_…subclass while the observer is still registered, and the laterremoveObserver:forKeyPath:raisesNSRangeException. AppKit registers such observers itself on the first responder, so apps crash when their window is closed.With this change, the previous class is only restored if ours is still the view's class. Otherwise the view keeps our subclass and its associated object until it is deallocated.
The new test adds an observer, drops the adapter and removes the observer. It has to run on the main thread, so it uses
harness = false; tell me if you'd prefer it done differently.cargo test -p accesskit_macospasses on Rust 1.87 and on stable. I also tested manually with the same change applied to accesskit_macos 0.26.3 on macOS 27.0.1: the crash no longer happens.