Skip to content

libobs: Return no main video before video is set up - #2252

Merged
rdoupe merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/output-before-video
Oct 24, 2026
Merged

rdoupe merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/output-before-video

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2237

What and why

Creating a raw output (one without OBS_OUTPUT_ENCODED) after obs_startup() but before obs_reset_video() crashed. obs_output_create() stores obs_get_video() in every such output, and obs_get_video() read obs->data.main_canvas->mix->video, but the main canvas has no mix until the first obs_reset_video().

Only a caller that creates an output before setting up video gets there: a plugin, a script or a headless tool. The frontend always resets video first. Upstream has the same code.

obs_get_video() now returns NULL when the main canvas has no mix, as obs_canvas_get_video() does for any canvas and as obs_get_video_info() returns false. The output is created with no video, like an output given NULL video by obs_output_set_media():

  • its size is 0x0;
  • obs_output_can_begin_data_capture() and obs_output_begin_data_capture() refuse it, so it cannot start.

The output start path needed no other change. Once video is set up, obs_get_video() returns the same video_t as before, so every output created after that is unchanged. An output created before video keeps no video after a later obs_reset_video() until one is set with obs_output_set_media().

RED → GREEN

  • RED commit: 3396152 (evidence taken on ee92925c6, the same commit before the rebase onto current master). test_output_before_video runs each case in a forked child (obs_startup() to obs_shutdown()). All 4 cases fail on the C backend, the hybrid libobs and libobs-c-reference: the child dies with SIGSEGV in obs_output_create() before video.
  • GREEN: 4711d14. The full ctest and the gates ran on 72542fa69, the same commit before the rebase; after the rebase the new test, the 36 output tests, the exports and the lint lane ran again with the same results.
    • test_output_before_video 4/4 on all three. The cases: the issue's output (flags 0) and a raw video output are created with no video; starting the raw one fails cleanly; after a later obs_reset_video() a new raw output gets the main video, starts and receives frames.
    • Every cmocka test that creates an output (36 tests): 36/36 on the C backend, the hybrid libobs and libobs-c-reference, 0 skipped.
    • Full ctest under a private Xvfb and D-Bus with a fresh HOME: C backend 471/471, hybrid 491/491, 0 skipped.
    • Exports: 1766 on all three, identical sets.
    • ci/local_gate.py --test-diff origin/master (3736 nextest tests passed, 6 skipped), --lane lint and --lane cross: all ok.
  • Real app (UI, protocol output or logging changes): N/A. No UI, protocol or log change; the frontend resets video before it creates any output.

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)
  • 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
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

obs_output_create() stores obs_get_video() in every output without
OBS_OUTPUT_ENCODED, and obs_get_video() reads the main canvas's mix, which
is NULL until the first obs_reset_video(). Creating such an output after
obs_startup() and before obs_reset_video() crashes.

test_output_before_video runs each case in a forked child, from
obs_startup() to obs_shutdown(), and reports the stage a child died in:

- an output with no flags (the one from the issue) and a raw video output,
  created before video, must be created with no video (a size of 0x0 for
  the raw one) or not at all;
- starting that raw output must fail cleanly: start() runs,
  obs_output_can_begin_data_capture() refuses and the output is not active;
- after a later obs_reset_video(), a new raw output gets the main video and
  its size, starts and receives frames, and the one created before still
  has no video and still refuses to start.

Refs obs-rust#2237
obs_get_video() read obs->data.main_canvas->mix->video, but the main
canvas has no mix until the first obs_reset_video(). obs_output_create()
calls it for every output without OBS_OUTPUT_ENCODED, so creating such an
output after obs_startup() and before obs_reset_video() crashed: a plugin,
a script or a headless tool that creates outputs before setting up video.

obs_get_video() now returns NULL when there is no main canvas or it has no
mix, as obs_canvas_get_video() does for any canvas and as
obs_get_video_info() returns false. obs_output_create() then stores NULL,
like an output given NULL video by obs_output_set_media(): its size is 0x0
and obs_output_can_begin_data_capture() and
obs_output_begin_data_capture() refuse it, so it cannot start. The output
start path needed no other change. Once video is set up, obs_get_video()
returns the same video_t as before, so every output created after that is
unchanged.

Fixes obs-rust#2237
@rdoupe
rdoupe requested a review from zackees as a code owner October 24, 2026 22:13
@rdoupe
rdoupe added this pull request to the merge queue Oct 24, 2026
Merged via the queue into obs-rust:master with commit 2f35ddf Oct 24, 2026
35 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.

libobs: Creating a raw output before obs_reset_video crashes in obs_get_video

1 participant