Repository navigation
Description
Found by our own characterization test test_hotkey_bindings_codec (#1622), which pins both as "characterized, not endorsed", and kept as is by the port in #1628 (#1621 lists them as follow-ups). No upstream report: upstream OBS master has the same code in libobs/obs-hotkey.c (load_binding() since the 2014 commit that added global hotkeys, load_bindings() since "libobs: Do not send hotkey_bindings_changed if nothing changed", 2023), and searches of obsproject/obs-studio issues ("OBS_KEY_NONE", "hotkey_bindings_changed", "hotkeys not saved", "obs_hotkey_load", "hotkey binding empty", and others) find no report of either.
Location
libobs/obs-hotkey-bindings.c.h,obs_hotkey_combination_from_data()(the parse ofload_binding()inobs-hotkey.c.h), and its Rust portcombo_from_fields()inrust/obs-hotkey/src/bindings.rs: the checkif (!modifiers && (combo.key == OBS_KEY_NONE || combo.key >= OBS_KEY_LAST_VALUE))is meant to drop an item with no modifiers and no known key, butmodifiersis&combo.modifiers, a pointer that is never NULL. So nothing is ever dropped (the Rust port returns a combination every time, to match).libobs/obs-hotkey.c.h,load_bindings(): it sendshotkey_bindings_changedonlyif (count), the number of array items.obs_hotkey_load()andobs_hotkey_pair_load()first callremove_bindings()and ignore what it returns, so an empty or NULL array removes the hotkey's bindings and sends nothing.obs_hotkey_load_bindings()keeps that result and signalsif (num || changed).
Class
Logic bug, data hygiene. No crash, no memory error, and nothing reachable beyond what a saved file can already set (a binding that never fires).
How it is reached
- Empty bindings: any hotkey array in a profile (
[Hotkeys]in basic.ini) or scene collection (a source's"hotkeys") with an item like{},{"key":""},{"key":"OBS_KEY_NOT_A_KEY"}(a key name from another build or a typo), a non-string"key", or{"key":"OBS_KEY_NONE"}. Each loads as a binding ofOBS_KEY_NONEwith no modifiers. It can never fire (handle_binding()resets a modifier-lessOBS_KEY_NONE), but it stays in the bindings list and every save writes it back as{"key":"OBS_KEY_NONE"}, so the junk never leaves the file. Modifier-only bindings ({"shift":true}) are real hotkeys thathandle_binding()fires, and are not affected. - No signal:
OBSBasic::CreateHotkeys()loads every frontend hotkey withobs_hotkey_load()/obs_hotkey_pair_load(), from the profile'sbindingsarray, which is missing for a hotkey the profile doesn't bind. Scripts and plugins callobs_hotkey_load()too. When such a load clears bindings, the listeners ofhotkey_bindings_changed(Settings > Hotkeys' widgets, and on Wayland the global-shortcut sync, which rebinds the portal shortcut set after that signal) are not told.
Reproduced in the current release
Headless (private Xvfb, private D-Bus, fresh HOME). The real app: a scene collection whose media source has "libobs.mute":[{},{"key":"bogus"}], "libobs.unmute":[{"key":"OBS_KEY_NONE"},{"key":"OBS_KEY_F7"}] and "libobs.push-to-talk":[{"shift":true}]; start OBS, quit (SIGTERM, clean shutdown saves the collection), read what was saved. The test: test_hotkey_bindings_codec with the fix's expectations, linked against each build's libobs.
| Build | Case | Result |
|---|---|---|
| v0.1.0-beta.20261018 AppImage | the scene collection above, start and quit | saved "libobs.mute":[{"key":"OBS_KEY_NONE"},{"key":"OBS_KEY_NONE"}], unmute keeps {"key":"OBS_KEY_NONE"} next to F7 |
| v0.1.0-beta.20261018 AppImage (its libobs) | test_hotkey_bindings_codec |
3 of 18 fail: junk items saved back as [{"key":"OBS_KEY_NONE"}]; obs_hotkey_load() with [] clears the bindings with no hotkey_bindings_changed; a pair's {} saved back |
| master d412d8b, libobs (C backend), hybrid libobs, libobs-c-reference | test_hotkey_bindings_codec |
the same 3 of 18 fail |
Fix
In obs_hotkey_combination_from_data() and its Rust port, test combo.modifiers instead of its address, as the 2014 code intended: an item with no modifiers and no known key loads as nothing, so it is also not saved again. Modifier-only bindings are kept. Existing files with {"key":"OBS_KEY_NONE"} entries load without error; those entries are dropped and gone after the next save. In load_bindings(), also send hotkey_bindings_changed when the caller's remove_bindings() removed something, as obs_hotkey_load_bindings() does, so clearing a hotkey with an empty or missing array signals once, and clearing a hotkey that had no bindings still sends nothing. No format change. PR follows.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
libobs: Drop empty hotkey bindings and signal when a load clears them
libobs: Drop empty hotkey bindings and signal when a load clears them (…