Keyboard handlers use a null xkb_state after a keymap that did not load, and each keymap leaks the previous one #167
Labels
No labels
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Catcrafts/Crafter.Graphics#167
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Device::keyboard_keymapreturns without making anxkb_statewhen the keymap is notXKB_V1or cannot be mapped, and makes one from an uncheckedxkb_keymap_new_from_stringresult.keyboard_modifiersandkeyboard_keythen passxkb_stateto libxkbcommon unchecked, which crashes on null. The same class of bug as #162: something the compositor decides, used unchecked. Line numbers refer to670df31.Details
implementations/Crafter.Graphics-Device.cpp:547-558: a format other thanWL_KEYBOARD_KEYMAP_FORMAT_XKB_V1(the protocol also hasNO_KEYMAP) or a failedmmapreturns early, andxkb_state(interfaces/Crafter.Graphics-Device.cppm:108) stays null.:561-565:xkb_keymap_new_from_stringreturns null for a keymap this libxkbcommon cannot compile, andxkb_state_newis called on it regardless.:640:keyboard_modifierscallsxkb_state_update_mask(xkb_state, ...). A compositor sends modifiers right after a keyboard enter, so this crashes as soon as a window gets the keyboard focus, before a key is pressed.:610:keyboard_keycallsxkb_state_key_get_utf8(xkb_state, ...)on every press.Also: every keymap event makes a new context (
:560, besides the one the static initializer makes,Device.cppm:107), keymap and state, and releases none of the previous ones. The compositor sends a new keymap whenever the layout changes.Found by reading the code; not reproduced.
Suggested fix
Key events need no keymap: the library reports raw kernel codes (
:593), and XKB only produces the UTF-8 foronTextInput. Without a state, skip the XKB calls, so keys still fireonRawKeyDownandonRawKeyUp, just without text. Inkeyboard_keymap, check the keymap before making a state, unref the previous state and keymap once the new ones exist, and keep one context.