Fix EXC_BAD_ACCESS when clicking grouped toolbar buttons#393
Merged
Conversation
selectedToolbarItemGroupItem: was invoking the selected toolbar item's action via a raw IMP cast to void (*)(id), passing only self. Objective-C methods actually have the ABI signature (id self, SEL _cmd, id sender, ...), so on ARM64 the _cmd (x1) and sender (x2) registers were left with whatever garbage the caller's frame happened to contain. This produced nonsense senders such as 0x400000000000bad0 and intermittent EXC_BAD_ACCESS crashes when the invoked IBAction (or its responder-chain / menu validation) touched sender. Replace the raw IMP call with performSelector:withObject:, which goes through objc_msgSend and correctly sets up self, _cmd, and sender. The NSToolbarItem is passed as the sender, matching the semantics of a normal toolbar click.
Owner
|
Thanks for the PR, @yusufm! Nicely tracked down — the ARM64 ABI mismatch explanation in the PR description is a great reference for anyone who hits a similar issue. Merging. Generated by Claude Code |
This was referenced Apr 21, 2026
Closed
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.
Problem
Clicking any grouped toolbar button (Shift Left/Right, Bold/Italic/Underline, H1/H2/H3, Lists) could crash the app with
EXC_BAD_ACCESS. Debugging showed the invoked IBAction was entered with a nonsensesendersuch as0x400000000000bad0.Root cause
-[MPToolbarController selectedToolbarItemGroupItem:]invoked the selected toolbar item's action via a raw IMP cast:Objective-C methods actually have the ABI signature
(id self, SEL _cmd, id sender, ...). The cast tovoid (*)(id)only passesself, so on ARM64 the_cmd(x1) andsender(x2) registers were left holding whatever garbage the caller's frame happened to contain. That garbage surfaced as bogus sender pointers (e.g.0x400000000000bad0) and intermittentEXC_BAD_ACCESSonce the invoked action (or its responder-chain / menu validation) touchedsender.Fix
Replace the raw IMP call with
performSelector:withObject:, which goes throughobjc_msgSendand correctly sets upself,_cmd, and thesenderargument. TheNSToolbarItemis passed as the sender, matching the semantics of a normal toolbar click.Testing
Manual: clicked every grouped toolbar item (Bold, Italic, Underline, H1/H2/H3, Ordered/Unordered List, Shift Left/Right) — no more crashes; all actions take effect on the document.