Skip to content

Fix sig 11 crash on macOS when using a Japanese (or possibly other CJK type) keyboard #1652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2025

Conversation

john-at-charpa
Copy link

Greetings,

I recently attempted to bathe in the nostalgia that is gameflorist/dunedynasty and immediately encountered a signal 11 crash. At first I assumed the problem was dunedynasty, but enough messing about with lldb showed me that it was actually liballegro5 that was crashing. Enough debugging with a -pg build showed me:

frame #2: 0x00000001050cb36c
liballegro.5.2.10.dylib`_al_osx_keyboard_handler(pressed=,
event=0x000060000390c300, dpy=0x0000000125832200) at keybd.m:280:69 [opt]

Digging a bit further I found that this is actually a fairly common problem; if you use a CJK type layout (Chinese, Japanese, or Korean) you can trigger it fairly easily. Discussions with suggested code fixes can be seen in places like:

https://github.com/microsoft/node-native-keymap/blob/main/src/keyboard_mac.mm
microsoft/vscode#23833

This PR fixes the issue with relatively the same method. The spice code must flow.

Cheers

@john-at-charpa
Copy link
Author

I should also mention that I did do a fair amount of due diligence when it came to the check for layout_data. I was unable to find a single example where a second null check against layout_data was done. Most everyone either returned (which cannot be done here as it is void) or did nothing at all. It looks like (despite a certain company vanishing API docs) TISCopyCurrentKeyboardLayoutInputSource will always return something, so in theory layout_data will never be null.

Interestingly enough the actual cause of the crash is this (when keyboard_input is logged):

2025-07-08 15:34:53.097 dunedynasty[5365:98712406] The first attempt at keyboard input is <TSMInputSource 0x6000027e8ec0> Input Mode: com.apple.inputmethod.Roman (Parent = com.apple.inputmethod.Kotoeri.RomajiTyping)

2025-07-08 15:34:53.097 dunedynasty[5365:98712406] The second attempt at keyboard input is <TSMInputSource 0x6000027a39c0> KB Layout: ABC (id=252)

You can see in the first instance, where TISCopyCurrentKeyboardInputSource is used, the result is actually the Input Method (in my case, Japanese but a Romaji input system).

Either way, I'm fairly confident that this fix is sufficient.

@SiegeLord
Copy link
Member

Wow, how gnarly! I'll give this a test, but otherwise this looks good. Thanks!

@john-at-charpa john-at-charpa changed the title Fix sig 11 crash when using a Japanese (or possibly other CJK type) keyboard Fix sig 11 crash on macOS when using a Japanese (or possibly other CJK type) keyboard Jul 9, 2025
@SiegeLord
Copy link
Member

I tested it, it seems to work good. One thing I noticed is that it doesn't pop up the IEM composition (i.e. multi-key strokes don't work for some reason), but at least it doesn't crash. Thanks again!

@SiegeLord SiegeLord merged commit d948d3f into liballeg:master Jul 19, 2025
3 checks passed
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.

2 participants