Skip to content

libobs: Answer "no video" from main canvas mix readers before video setup - #2266

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/main-canvas-mix-null
Oct 25, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/main-canvas-mix-null

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2253

What and why

Several libobs functions read obs->data.main_canvas->mix without checking it, and the main canvas has no mix until the first obs_reset_video(). Called after obs_startup() and before video is set up, each of them crashed:

  • obs_get_main_texture();
  • obs_add_raw_video_callback2() (and obs_add_raw_video_callback(), which calls it) and obs_remove_raw_video_callback();
  • obs_nv12_tex_active() and obs_p010_tex_active();
  • get_scene_dimensions() in obs-scene.c.h. It reads the main canvas for a scene item with no parent scene (an item removed from its scene) or in a group without a canvas. Through it, obs_sceneitem_get_pos(), _get_scale(), _get_bounds(), _get_info2() and their setters crashed for such an item in relative coordinates.

Only a plugin, script or headless tool that calls these before video setup gets there. The frontend always resets video first. Upstream has the same code. It is the same class as #2237 (obs_get_video(), fixed in #2252).

Each function now checks the main canvas and its mix first and answers as there is no video:

  • obs_get_main_texture() returns NULL, as it does before the first frame is rendered;
  • adding a raw video callback logs a warning and does not add it; it is not kept for later;
  • removing a raw video callback does nothing, since none can have been added;
  • obs_nv12_tex_active() and obs_p010_tex_active() return false;
  • get_scene_dimensions() gives 0x0, as scene_getwidth() and scene_getheight() already answer for a scene before video exists.

Once video is set up, every call reads the same mix as before and is unchanged.

A grep of libobs for other main_canvas and main_canvas->mix reads found no other unchecked one reachable before video setup. obs_get_video_info(), obs_view_main_mix_info(), scene_getwidth()/scene_getheight(), obs_get_video_frame_counts(), the main texture render calls and the FPS sharing in the video reset already check the mix.

RED → GREEN

  • RED commit: bcd42c6. Its evidence was taken on 2fcd6861d, the same commit before the rebases onto current master. test_main_mix_before_video runs each case in a forked child (obs_startup() to obs_shutdown()) and reports the stage a child died in. On the C backend, the hybrid libobs and libobs-c-reference, all 6 "before video" cases fail: the child dies with SIGSEGV in the call before video is set up. The 5 "after reset" cases pass, since they only make the calls after obs_reset_video().
  • GREEN: 28f9cc7. The full ctest and the --test-diff and --lane cross gates ran on 562c68099, the same change before the rebases onto current master. After the last rebase, the new test, the focused tests, the exports and the lint lane ran again with the same results.
    • test_main_mix_before_video 11/11 on all three. Before video: no main texture; both raw callback adds are refused with a warning and never called after a later reset; removing one does nothing; NV12 and P010 texture output are not active; a removed item's scale and position are those of a 0x0 canvas. After obs_reset_video(): the main texture appears once a frame is rendered, a raw callback receives frames and stops once removed, NV12 and P010 texture output match what the GPU offers for that format, and the removed item is scaled to the main canvas.
    • Every cmocka test that calls the changed functions, or reads scene item positions, scales or bounds (49 tests, with the deinterlace field order test's 5 rate variants; with the new test and, after the rebase, test_output_before_video): 51/51 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 473/473, hybrid 494/494, 0 skipped.
    • Exports: 1766 on all three, identical sets.
    • ci/local_gate.py --test-diff origin/master (3779 nextest tests passed, 6 skipped), --lane lint and --lane cross: all ok.
  • Real app (UI, protocol output or logging changes): N/A. The new warning is logged only when a raw video callback is added before video is set up; the frontend resets video first. No UI or protocol change.

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_get_main_texture(), obs_add_raw_video_callback2() (and
obs_add_raw_video_callback(), which calls it),
obs_remove_raw_video_callback(), obs_nv12_tex_active(),
obs_p010_tex_active() and get_scene_dimensions() in obs-scene.c.h read
obs->data.main_canvas->mix without checking it. The main canvas has no mix
until the first obs_reset_video(), so each of them crashes when called
after obs_startup() and before video is set up. get_scene_dimensions()
reads the main canvas for a scene item with no parent scene: here the
position and scale of an item removed from its scene.

test_main_mix_before_video runs each case in a forked child, from
obs_startup() to obs_shutdown(), and reports the stage a child died in.
Each "before video" case calls its function before obs_reset_video() and
expects the "no video" answer:

- obs_get_main_texture(): NULL;
- adding a raw video callback: refused with a warning, and the callback is
  still never called after a later obs_reset_video();
- removing a raw video callback: nothing;
- obs_nv12_tex_active() and obs_p010_tex_active(): false;
- a removed item's scale and position: those of a 0x0 canvas, as a scene
  without a custom size has before video is set up.

Each case then resets video and checks the call works normally: the main
texture once a frame is rendered, a raw callback that receives frames and
stops once removed, the texture conversion the GPU gives for NV12 and
P010, and the removed item scaled to the main canvas. The "after reset"
cases make only those calls, as the frontend does, and pass with or
without the fix.

Refs obs-rust#2253
…etup

obs_get_main_texture(), obs_add_raw_video_callback2(),
obs_remove_raw_video_callback(), obs_nv12_tex_active(),
obs_p010_tex_active() and get_scene_dimensions() read
obs->data.main_canvas->mix, but the main canvas has no mix until the first
obs_reset_video(). Called after obs_startup() and before video is set up,
each of them crashed: a plugin, a script or a headless tool that calls
them early. The frontend resets video first.

Each now checks the main canvas and its mix first and answers as there is
no video:

- obs_get_main_texture() returns NULL, as it does before the first frame;
- obs_add_raw_video_callback2() (and obs_add_raw_video_callback()) logs a
  warning and does not add the callback, which is not kept for later;
- obs_remove_raw_video_callback() does nothing: no callback can have been
  added;
- obs_nv12_tex_active() and obs_p010_tex_active() return false;
- get_scene_dimensions() gives 0x0, as scene_getwidth() and
  scene_getheight() already answer for a scene without a custom size.

Once video is set up, every call reads the same mix as before and is
unchanged.

Fixes obs-rust#2253
@rdoupe
rdoupe requested a review from zackees as a code owner October 24, 2026 23:44
@zackees
zackees enabled auto-merge October 24, 2026 23:49
@zackees
zackees added this pull request to the merge queue Oct 24, 2026
Merged via the queue into obs-rust:master with commit da8090c Oct 25, 2026
35 checks passed
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In review to Done in obs-rust Multiview Oct 25, 2026
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: More functions dereference the main canvas mix before video is set up

2 participants