Repository navigation
libobs: Answer "no video" from main canvas mix readers before video setup - #2266
Merged
Merged
Conversation
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
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 #2253
What and why
Several libobs functions read
obs->data.main_canvas->mixwithout checking it, and the main canvas has no mix until the firstobs_reset_video(). Called afterobs_startup()and before video is set up, each of them crashed:obs_get_main_texture();obs_add_raw_video_callback2()(andobs_add_raw_video_callback(), which calls it) andobs_remove_raw_video_callback();obs_nv12_tex_active()andobs_p010_tex_active();get_scene_dimensions()inobs-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;obs_nv12_tex_active()andobs_p010_tex_active()return false;get_scene_dimensions()gives 0x0, asscene_getwidth()andscene_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_canvasandmain_canvas->mixreads 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
test_main_mix_before_videoruns each case in a forked child (obs_startup()toobs_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 afterobs_reset_video().--test-diffand--lane crossgates 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_video11/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. Afterobs_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.test_output_before_video): 51/51 on the C backend, the hybrid libobs and libobs-c-reference, 0 skipped.ci/local_gate.py --test-diff origin/master(3779 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