Repository navigation
libobs: Return no main video before video is set up - #2252
Merged
Merged
Conversation
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
This was referenced Oct 24, 2026
4 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2237
What and why
Creating a raw output (one without
OBS_OUTPUT_ENCODED) afterobs_startup()but beforeobs_reset_video()crashed.obs_output_create()storesobs_get_video()in every such output, andobs_get_video()readobs->data.main_canvas->mix->video, but the main canvas has no mix until the firstobs_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, asobs_canvas_get_video()does for any canvas and asobs_get_video_info()returns false. The output is created with no video, like an output given NULL video byobs_output_set_media():obs_output_can_begin_data_capture()andobs_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 samevideo_tas before, so every output created after that is unchanged. An output created before video keeps no video after a laterobs_reset_video()until one is set withobs_output_set_media().RED → GREEN
test_output_before_videoruns each case in a forked child (obs_startup()toobs_shutdown()). All 4 cases fail on the C backend, the hybrid libobs and libobs-c-reference: the child dies with SIGSEGV inobs_output_create()before video.test_output_before_video4/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 laterobs_reset_video()a new raw output gets the main video, starts and receives frames.ci/local_gate.py --test-diff origin/master(3736 nextest tests passed, 6 skipped),--lane lintand--lane cross: all ok.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC