From 48653f5779045f7e10772e2354374a1f41b28276 Mon Sep 17 00:00:00 2001 From: Ryan Doupe Date: Sat, 21 Nov 2026 06:34:02 -0500 Subject: [PATCH 1/2] test(libobs): require obs_wait_for_destroy_queue to sync with video-only cores (Refs #5405) Co-Authored-By: Claude Opus 5.5 --- test/cmocka/test_destroy_queue_video_sync.c | 114 ++++++++++++++++++ .../test_destroy_queue_video_sync.cmake | 16 +++ 2 files changed, 130 insertions(+) create mode 100644 test/cmocka/test_destroy_queue_video_sync.c create mode 100644 test/cmocka/tests.d/test_destroy_queue_video_sync.cmake diff --git a/test/cmocka/test_destroy_queue_video_sync.c b/test/cmocka/test_destroy_queue_video_sync.c new file mode 100644 index 0000000000..385bde8e67 --- /dev/null +++ b/test/cmocka/test_destroy_queue_video_sync.c @@ -0,0 +1,114 @@ +/* obs_wait_for_destroy_queue() must wait for the video thread whenever it + * runs, also when audio was never reset. tick_sources() holds a reference + * on every source while it ticks it; a caller that waits for the destroy + * queue and then checks a weak reference raced that tick (the master push + * failure of test_scene_item_transition_serialization_lifetime). */ +#include +#include +#include +#include +#include +#include "util/platform.h" +#include "util/threading.h" +#include "obs.h" + +static os_event_t *tick_entered; +static volatile long hold_next_tick; + +static const char *fixture_name(void *data) +{ + (void)data; + return "destroy queue sync fixture"; +} +static void *fixture_create(obs_data_t *settings, obs_source_t *source) +{ + (void)settings; + return source; +} +static void fixture_destroy(void *data) +{ + (void)data; +} +static uint32_t fixture_size(void *data) +{ + (void)data; + return 0; +} +static void fixture_tick(void *data, float seconds) +{ + (void)data; + (void)seconds; + if (os_atomic_set_long(&hold_next_tick, 0)) { + os_event_signal(tick_entered); + /* Keep tick_sources()' reference while the test releases its own. */ + os_sleep_ms(500); + } +} +static int setup(void **state) +{ + (void)state; + if (os_event_init(&tick_entered, OS_EVENT_TYPE_AUTO) != 0) + return -1; + if (!obs_startup("en-US", NULL, NULL)) + return -1; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + obs_add_data_path(TEST_LIBOBS_DATA_PATH); +#pragma GCC diagnostic pop + struct obs_video_info video = {.graphics_module = GRAPHICS_MODULE_PATH, + .fps_num = 30, + .fps_den = 1, + .base_width = 64, + .base_height = 64, + .output_width = 64, + .output_height = 64, + .output_format = VIDEO_FORMAT_NV12, + .colorspace = VIDEO_CS_709, + .range = VIDEO_RANGE_PARTIAL, + .scale_type = OBS_SCALE_BICUBIC}; + /* Video only: no obs_reset_audio(), like most core-video fixtures. */ + if (obs_reset_video(&video) != OBS_VIDEO_SUCCESS) { + obs_shutdown(); + return -1; + } + struct obs_source_info info = {.id = "destroy_queue_sync_fixture", + .type = OBS_SOURCE_TYPE_INPUT, + .output_flags = OBS_SOURCE_VIDEO, + .get_name = fixture_name, + .create = fixture_create, + .destroy = fixture_destroy, + .get_width = fixture_size, + .get_height = fixture_size, + .video_tick = fixture_tick}; + obs_register_source(&info); + return 0; +} +static int teardown(void **state) +{ + (void)state; + obs_shutdown(); + os_event_destroy(tick_entered); + return 0; +} +static void wait_covers_a_tick_in_progress(void **state) +{ + (void)state; + obs_source_t *source = obs_source_create_private("destroy_queue_sync_fixture", "Ticked", NULL); + assert_non_null(source); + obs_weak_source_t *weak = obs_source_get_weak_source(source); + + os_atomic_set_long(&hold_next_tick, 1); + assert_int_equal(os_event_timedwait(tick_entered, 5000), 0); + obs_source_release(source); + assert_false(obs_weak_source_expired(weak)); /* the tick still holds it */ + + while (obs_wait_for_destroy_queue()) + ; + assert_true(obs_weak_source_expired(weak)); + obs_weak_source_release(weak); +} +int main(void) +{ + const struct CMUnitTest tests[] = {cmocka_unit_test(wait_covers_a_tick_in_progress)}; + return cmocka_run_group_tests(tests, setup, teardown); +} diff --git a/test/cmocka/tests.d/test_destroy_queue_video_sync.cmake b/test/cmocka/tests.d/test_destroy_queue_video_sync.cmake new file mode 100644 index 0000000000..43b92b71f0 --- /dev/null +++ b/test/cmocka/tests.d/test_destroy_queue_video_sync.cmake @@ -0,0 +1,16 @@ +# The video thread must be running for obs_wait_for_destroy_queue() to sync with it. +if(OS_LINUX) + add_executable(test_destroy_queue_video_sync test_destroy_queue_video_sync.c) + target_include_directories( + test_destroy_queue_video_sync + PRIVATE ${CMOCKA_INCLUDE_DIR} "${CMAKE_SOURCE_DIR}/deps/libcaption" + ) + target_link_libraries(test_destroy_queue_video_sync PRIVATE OBS::libobs ${CMOCKA_LIBRARIES}) + target_compile_definitions( + test_destroy_queue_video_sync + PRIVATE TEST_LIBOBS_DATA_PATH="${CMAKE_SOURCE_DIR}/libobs/data/" GRAPHICS_MODULE_PATH="$" + ) + add_dependencies(cmocka-tests test_destroy_queue_video_sync) + add_test(NAME test_destroy_queue_video_sync COMMAND test_destroy_queue_video_sync) + set_tests_properties(test_destroy_queue_video_sync PROPERTIES TIMEOUT 30) +endif() From 9cc21bd54cc4c5c3f73bc15abcbe5712c328d8d0 Mon Sep 17 00:00:00 2001 From: Ryan Doupe Date: Sat, 21 Nov 2026 06:34:08 -0500 Subject: [PATCH 2/2] libobs: wait for the video thread in obs_wait_for_destroy_queue without audio (Fixes #5405) tick_sources() holds a reference on every source while it ticks it. The wait synced with the video thread only when audio was reset too, so a video-only core could still see that reference after the wait. Co-Authored-By: Claude Opus 5.5 Ci-Attestation: {"at":1795261934,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":93,"stamp":"c5eaf942897bcd1f422a8b60442d57b0","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261934,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":93,"stamp":"4ac391a4b3a8ffa02b13eacf8ab201e6","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261934,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":93,"stamp":"eaacf6d3920aba2708314cd2042ba21d","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261934,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":93,"stamp":"d5811bcbe181e0da0ca79998d7006d57","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261840,"gate":"general/all/client-lint","host":"linux-x86_64","key":"e6ff4ccf3bc027728b53e77c479a8a75244be240d81ee8e0e6eddcbb404d9486","lane":"client-lint","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":61,"stamp":"ed7d73df2c2ed43390f3ebd7572edf1a","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261934,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":93,"stamp":"79bdb662e897beb93107a44f8729a811","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261840,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"e6ff4ccf3bc027728b53e77c479a8a75244be240d81ee8e0e6eddcbb404d9486","lane":"client-lint","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":61,"stamp":"ffbf121a3632a4f4903cd377f05aa01b","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261840,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"e6ff4ccf3bc027728b53e77c479a8a75244be240d81ee8e0e6eddcbb404d9486","lane":"client-lint","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":61,"stamp":"2d95b536ca89b76741c1df08c6a35141","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261840,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"e6ff4ccf3bc027728b53e77c479a8a75244be240d81ee8e0e6eddcbb404d9486","lane":"client-lint","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":61,"stamp":"779ce90ec8b9fb2ca425681cf100882f","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261840,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"e6ff4ccf3bc027728b53e77c479a8a75244be240d81ee8e0e6eddcbb404d9486","lane":"client-lint","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":61,"stamp":"d372e982ea189c2a37622e233223cfda","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261840,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"e6ff4ccf3bc027728b53e77c479a8a75244be240d81ee8e0e6eddcbb404d9486","lane":"client-lint","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":61,"stamp":"f24c0742821c1e21c7cc94217a157976","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261840,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"e6ff4ccf3bc027728b53e77c479a8a75244be240d81ee8e0e6eddcbb404d9486","lane":"client-lint","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":61,"stamp":"3bcbf02ba45160a3584aa992397fac00","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261840,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"e6ff4ccf3bc027728b53e77c479a8a75244be240d81ee8e0e6eddcbb404d9486","lane":"client-lint","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":61,"stamp":"c73f6f7699227cb1dbcead3634832e86","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261840,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"e6ff4ccf3bc027728b53e77c479a8a75244be240d81ee8e0e6eddcbb404d9486","lane":"client-lint","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":61,"stamp":"09b7c0bbdf2d1ca79113d41023fa9537","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261840,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"e6ff4ccf3bc027728b53e77c479a8a75244be240d81ee8e0e6eddcbb404d9486","lane":"client-lint","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":61,"stamp":"77f27582b80884738c18f5b1b5e24da9","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261840,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"e6ff4ccf3bc027728b53e77c479a8a75244be240d81ee8e0e6eddcbb404d9486","lane":"client-lint","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":61,"stamp":"06d8ecf5626c0a90cfee6d47f3b7cfbc","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261840,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"e6ff4ccf3bc027728b53e77c479a8a75244be240d81ee8e0e6eddcbb404d9486","lane":"client-lint","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":61,"stamp":"9da33f7ea60f9450fe7066cf8f93cfde","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795261840,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"e6ff4ccf3bc027728b53e77c479a8a75244be240d81ee8e0e6eddcbb404d9486","lane":"client-lint","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":61,"stamp":"862dfc946df5c7a75e018819ad42fb12","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Ci-Attestation: {"at":1795262137,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"d2c80fc87f0aca35e6e4986b369363fb3168d152838ec71fcd4ef3d166353a71","lane":"client-test-x86_64-unknown-linux-gnu","parents":["48653f5779045f7e10772e2354374a1f41b28276"],"secs":202,"stamp":"afb7f6b6a0d69907724ca790869b1f69","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc","v":1,"via":"run"} Client-Checks: {"checks":{"base":"6bf1f673cbd5dde32e069bfec5135e17dd013c55","coverage":"all-tracked-applicable-files","diff":["libobs/obs.c.h","test/cmocka/test_destroy_queue_video_sync.c","test/cmocka/tests.d/test_destroy_queue_video_sync.cmake"],"head":"0bccf89bc8cfbf12d18d9ce18fbdafbc808c5a0c","tools":{"orchestrator-python":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]","schema-dependencies":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21504-GITv2.15.4\n compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ICU ISO8859X Regexps Automata RelaxNG Schemas Schematron Modules Debug Zlib"},"tracked-digest":"6143fda329ffd1d4f82a494e923e5ea31664f4805cc4de01b463eab882be688b","tree":"78315c16114b8b2751db1b35576f6a6c687c2cfc"}} --- libobs/obs.c.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/libobs/obs.c.h b/libobs/obs.c.h index bc8f17161c..560bea5dfe 100644 --- a/libobs/obs.c.h +++ b/libobs/obs.c.h @@ -2948,17 +2948,25 @@ bool obs_wait_for_destroy_queue(void) { struct task_wait_info info = {0}; - /* allow video and audio threads time to release objects. Without them - * (no video reset) sources are still destroyed by the destruction - * thread, so that queue is waited for regardless. */ - if (obs->video.thread_initialized && obs->audio.audio) { + /* allow video and audio threads time to release objects. Each thread + * is waited for when it runs: video without audio still ticks sources + * and holds references on them while it does. Without either thread + * sources are still destroyed by the destruction thread, so that queue + * is waited for regardless. */ + const bool wait_video = obs->video.thread_initialized; + const bool wait_audio = obs->audio.audio != NULL; + if (wait_video || wait_audio) { if (os_event_init(&info.event, OS_EVENT_TYPE_AUTO) != 0) blog(LOG_WARNING, "obs_wait_for_destroy_queue: Failed to create the wait event, " "polling instead"); - obs_queue_task(OBS_TASK_GRAPHICS, task_wait_callback, &info, false); - task_wait_for_callback(&info); - obs_queue_task(OBS_TASK_AUDIO, task_wait_callback, &info, false); - task_wait_for_callback(&info); + if (wait_video) { + obs_queue_task(OBS_TASK_GRAPHICS, task_wait_callback, &info, false); + task_wait_for_callback(&info); + } + if (wait_audio) { + obs_queue_task(OBS_TASK_AUDIO, task_wait_callback, &info, false); + task_wait_for_callback(&info); + } os_event_destroy(info.event); }