Skip to content

libobs: Name the requested name in the rename warning, and take a NULL rename - #1804

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/context-rename-warning
Oct 22, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/context-rename-warning

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #1787 (PR 2 of the plan: the two rename fixes. The port follows.)

What and why

Two spec-following fixes in obs_context_data_setname_ht() (libobs/obs.c.h), the rename of a context that has a name table: public sources (obs_source_set_name()), sources that need a canvas, such as scenes (obs_canvas_rename_source()), and public canvases (obs_canvas_set_name()). #1788 pinned both as "characterized, not endorsed". The dedup in obs-context-names.c.h is not changed.

  • The rename warning names the requested name. The warning printed context->name as the duplicate. At that point context->name is still the old name: it has only been pushed to the rename cache. So a rename of "C" to "A" while "A" is taken logged Attempted to rename context to duplicate name "C"! New name has been changed to "A 2". It now logs duplicate name "A", as the insert warning (obs_context_data_insert_name()) already names the requested name. The resulting name, "A 2", is unchanged.
  • A NULL rename no longer crashes. obs_source_set_name(source, NULL) on a public source, or on a source that needs a canvas, passed NULL to the dedup lookup, whose HASH_FIND_STR calls strlen() on it. That crashed as soon as the table held another context (with the table otherwise empty, the optimized build tested here skipped the strlen(), so the crash depends on what else is loaded). Only a plugin or script can pass NULL; obs-websocket refuses an empty or missing name. Now a NULL name skips the lookup and goes to dup_name(), which gives it the next unnamed name ("__unnamed%04lld"), as an empty rename gets.

Why the unnamed name and not "ignore". obs_source_set_name() already treats NULL like an empty name: its guard lets both through as a rename, and only the public path then crashed. The rest of the API does the same:

  • obs_source_create() with NULL gets an unnamed name, as with "".
  • A rename to "" gets an unnamed name.
  • A private source renamed to NULL already goes through dup_name() and becomes nameless again, as a private source created with NULL is. The test pins that, and this change leaves it alone.

So a NULL rename now gets what a NULL name gets on create, on every path. Ignoring it, as obs_encoder_set_name() and obs_canvas_set_name() do (they ignore NULL and "" alike), would make NULL and "" differ for sources, and would change the private path, which works today. obs_canvas_set_name() returns before any rename for NULL, so canvases are not affected. The fix is one condition in obs_context_data_setname_ht(). obs_context_name_deduplicate() is unchanged and still passes a NULL name to exists() as it is (test_context_name_helpers pins that); obs.c no longer asks it with NULL.

Unchanged, and still pinned as "not endorsed":

  • Renaming "A 2" to "A" while "A" is taken leaves it "A 2", with the warning and a rename signal from "A 2" to "A 2". Only the warning text changes, from "A 2" to "A".
  • A rename to an empty name (and now a NULL one) takes the next unnamed name without making it unique.
  • unnamed_index is incremented without a lock.
  • Encoder, output and service names are not made unique.

Upstream (obsproject/obs-studio master, libobs/obs.c) has both bugs: the same context->name in the warning, and the same NULL into HASH_FIND_STR. The line is under "Fixed upstream bugs", Stability, in docs/features.md. I found no upstream issue for either.

Test expectation change (maintainer sign-off): this changes pinned "characterized, not endorsed" expectations in test_context_names, in test_rename:

  1. The rename of "C" to "A" while "A" is taken: the expected warning was Attempted to rename context to duplicate name "C"! New name has been changed to "A 2", and is now ... duplicate name "A"! .... The name, the rename signal and the lookups are unchanged.
  2. The rename of "A 2" to "A" while "A" is taken: the expected warning was ... duplicate name "A 2"! New name has been changed to "A 2", and is now ... duplicate name "A"! .... The result ("A 2", and the signal from "A 2" to "A 2") stays pinned and unchanged.

A new case, test_rename_null, covers the NULL rename that #1788 did not drive because it crashed: a public input and a source that needs a canvas, each with another source in its table, renamed to NULL get "__unnamed0000" and "__unnamed0001", with a rename signal and no warning, and their old names are free again. In test_context_name_helpers only a comment changes ("only a rename of a public source to NULL reaches it" is no longer true); none of its expectations change. Why: both are bugs. The warning named the wrong string, and the NULL rename crashed on API misuse that the rest of the API handles as "unnamed".

RED → GREEN

  • RED commit: f671fb87b test: Expect the requested name in the rename warning and a NULL rename. On master's libobs, test_context_names fails 2 of 15 on the C backend, the hybrid libobs and libobs-c-reference: test_rename ("... duplicate name "C"! ..." != "... duplicate name "A"! ..."), and test_rename_null, which crashes with a segmentation fault in the rename to NULL. The crash leaves libobs started, so the two cases after it (test_canvas_sources, test_canvases) skip in the RED run. test_context_name_helpers passes 12/12.
  • GREEN: fc6dd0b79 libobs: Name the requested name in the rename warning, and take a NULL rename. test_context_names 15/15 and test_context_name_helpers 12/12 against libobs with the C backend, the hybrid libobs and libobs-c-reference.
  • Local, two build trees: OBS_LIBOBS_BACKEND=C, and HYBRID with OBS_BUILD_C_REFERENCE=ON, both full builds. Full ctest -j4, headless (private Xvfb, private D-Bus, fresh HOME):
Lane Library ctest Exported symbols
OBS_LIBOBS_BACKEND=C libobs 367/369 (see below) IDENTICAL (1766)
HYBRID, OBS_BUILD_C_REFERENCE=ON hybrid libobs 371/371 IDENTICAL (1766)
HYBRID, OBS_BUILD_C_REFERENCE=ON libobs-c-reference 371/371 IDENTICAL (1766)

On the hybrid libobs and libobs-c-reference nothing was skipped or failed to run, on the final head (after the rebase onto #1800) and before it. On the C backend, test_audio_controls fails in its setup: obs_startup() fails when Xvfb resets between its cases (its ctest entry runs xvfb-run without -noreset). It fails the same way with master's obs.c.h, run alone, so it is not this change. test_pulse_stream_restart failed once in one C-backend run and passed in the other. Both context tests pass on that build. In one earlier hybrid run, test_pipewire_screencast_shm failed once and then passed 3 of 3 runs alone.

  • Also run: uv run ci/local_gate.py --lane lint passed. clang-format is clean on the changed files.
  • Real app (UI, protocol output or logging changes): not run in the app. The log change is one argument of an existing warning, and test_context_names checks the full text through the libobs log handler. The NULL rename is reachable only from a plugin or script.

Windows/macOS: not built there. The change has no platform conditional, and the new case uses only the public API, like the rest of test_context_names.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together) (the characterization is libobs: Move the context name helpers into obs-context-names.c #1788)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (not applicable: no port here)

The rename warning of obs_context_data_setname_ht() names the old name
as the duplicate: a rename of "C" to "A" logs 'duplicate name "C"'. It
should name the requested name, "A". The two rename cases of
test_context_names that pinned the old text now expect "A".

obs_source_set_name() with NULL on a public source passes NULL to
HASH_FIND_STR and crashes. test_rename_null expects what a NULL name gets
on create, and what an empty rename gets: the next unnamed name, for an
input and for a source that needs a canvas.

Refs obs-rust#1787
@rdoupe
rdoupe requested a review from zackees as a code owner October 22, 2026 17:07
…L rename

obs_context_data_setname_ht() logged context->name as the duplicate
name, but by then that is still the old name (it was only pushed to the
rename cache), so a rename of "C" to "A" logged 'duplicate name "C"'.
It now logs the requested name.

A NULL name went to the dedup lookup, whose HASH_FIND_STR calls strlen()
on it and crashed once the table held another context. A NULL rename now
skips the lookup and takes the unnamed name from dup_name(), as a NULL
name on create and an empty rename do. A private source keeps its NULL
name as before (obs_context_data_setname()).

Refs obs-rust#1787
@rdoupe
rdoupe force-pushed the fix/context-rename-warning branch from 53e88bf to fc6dd0b Compare October 22, 2026 17:07
@zackees
zackees added this pull request to the merge queue Oct 22, 2026
Merged via the queue into obs-rust:master with commit a42e50f Oct 22, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants