Skip to content

bug: libobs: hotkey loading keeps empty bindings and clears without hotkey_bindings_changed #1648

Closed

Description

@rdoupe

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 of load_binding() in obs-hotkey.c.h), and its Rust port combo_from_fields() in rust/obs-hotkey/src/bindings.rs: the check if (!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, but modifiers is &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 sends hotkey_bindings_changed only if (count), the number of array items. obs_hotkey_load() and obs_hotkey_pair_load() first call remove_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 signals if (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 of OBS_KEY_NONE with no modifiers. It can never fire (handle_binding() resets a modifier-less OBS_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 that handle_binding() fires, and are not affected.
  • No signal: OBSBasic::CreateHotkeys() loads every frontend hotkey with obs_hotkey_load() / obs_hotkey_pair_load(), from the profile's bindings array, which is missing for a hotkey the profile doesn't bind. Scripts and plugins call obs_hotkey_load() too. When such a load clears bindings, the listeners of hotkey_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions