Skip to content

libobs: Free and reset after unknown shader calls - #3626

Merged
zackees merged 4 commits into
masterfrom
fix/bug-ep-makeshaderstring-leaks-it-602
Nov 4, 2026
Merged

zackees merged 4 commits into
masterfrom
fix/bug-ep-makeshaderstring-leaks-it-602

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #3625

What and why

When a pass in an effect file names a vertex or pixel function the file doesn't define (a typo such as vertex_shader = VSDefualt(pos);), ep_makeshaderstring returns early after it has written the declarations of the params the call names. That return skips the two lines the success path ends with:

  • dstr_free(&call_str): the call string leaks every time the effect loads;
  • ep_reset_written(ep): those params stay marked as written, so the pass's next shader (and every later one, until a call succeeds) leaves their declarations out. The pixel shader then fails with undeclared-identifier errors that point away from the real mistake.

The vertex shader failing is expected. This PR makes the unknown-function return free the call string and reset the flags, the same as the success path, so only the shader with the typo fails and nothing leaks.

The fix is in C: the shader writer's Rust port waits on the function parser port and the writer's extraction. When it is ported it keeps this behaviour, with no intentional difference.

No upstream issue.

RED → GREEN

  • RED commit: 817e4d9 adds test_effect_parser_shader_call, which compiles the effect parser C into itself with gs_vertexshader_create and gs_pixelshader_create renamed to recorders that keep the shader text and return NULL, so ep_compile runs with no graphics device. On master test_unknown_vertex_call_resets_written fails (the pixel shader is missing uniform float4 color;) and test_unknown_vertex_call_frees fails (1 != 0: one allocation left after ep_free and effect_free); the control test_null_vertex_call passes.

  • GREEN: test_effect_parser_shader_call passes 3/3 on the C build, hybrid libobs and libobs-c-reference. Tier 2 in full: 730/730 on hybrid and 730/730 on libobs-c-reference, 3 skipped on each (test_pulse_default_follow, test_v4l2_vivid_replug, test_v4l2_vivid_stall: no matching device), test_source_monitor_only_load left out (it hangs with no sound server); the native-graphics tests, which load the real effects through this code with a GL device, 44/46 on all three builds with the other two being audio tests that time out with no sound server and pass when run alone. The exported symbol sets are identical on the C, hybrid and c-ref builds (1767 each). --test-diff: 6534 run, 6534 passed, 6 skipped. --lane lint and --lane cross: every step passes except the Dylint step, which can't run on the local host (no driver for the pinned nightly); MSVC clippy with --all-targets passes. Runs were on 96c0a284e.

  • Real app (UI, protocol output or logging changes): the Linux app (obs-studio-rust-gui --multi, headless under Xvfb on llvmpipe, a fresh profile, no audio output), started with a copy of its data where libobs's own repeat.effect, which loads at startup, has the typo vertex_shader = VSDefualt(vert_in, image);. It ran 25 s and was quit with SIGINT, once with master's libobs and once with this branch's, with nothing else changed. Master's log:

    device_vertexshader_create (GL) failed
    Pass (0) <> missing vertex shader!
    Error compiling shader:
    0:35(9): error: `image' undeclared
    0:35(9): error: unknown method: `Sample'
    0:35(2): error: `return' with wrong type error, in function `PSDrawBare' returning vec4
    device_pixelshader_create (GL) failed
    Pass (0) <> missing pixel shader!
    ...
    Number of memory leaks: 1
    

    This branch's log:

    device_vertexshader_create (GL) failed
    Pass (0) <> missing vertex shader!
    ...
    Number of memory leaks: 0
    

    Only the shader with the typo fails, the pixel shader's misleading errors are gone, and nothing leaks.

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)

A pass whose shader call names a function the effect doesn't define
makes ep_makeshaderstring() return before it frees the call string and
resets the written flags. The pass's pixel shader then leaves out the
params the failed call named, and the call string leaks.

The new test compiles the effect parser C into itself with the two
shader-create calls renamed to recorders, so ep_compile() runs with no
graphics device. It checks the pixel shader against a pass whose vertex
call is NULL, and that nothing is left allocated after ep_free() and
effect_free(). Both checks fail on master.

Refs #3625.
When a pass's shader call names a function the effect doesn't define,
ep_makeshaderstring() now frees the call string and resets the written
flags before it returns, as it does after a call that succeeds. Only the
shader with the bad call fails: the pass's other shader declares the
params that call named again, and the call string no longer leaks.

Fixes #3625.

Local-Gate: v1 tree=6ad2c637b4895e52e61ea1c2285eb74feadf04d1 secs=2198 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1793810969,"gate":"rust/all/fmt","host":"linux-x86_64","key":"c8e5b8c8ecb627702f6b239e667ab66355cf22d730a76cf2ff71a279148344e8","lane":"lint","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":69,"stamp":"330594638529efaafc9f1c81947b69bb","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
Ci-Attestation: {"at":1793810969,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"c8e5b8c8ecb627702f6b239e667ab66355cf22d730a76cf2ff71a279148344e8","lane":"lint","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":69,"stamp":"fc150300d15eab2c09a7a0e0e297db05","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
Ci-Attestation: {"at":1793810969,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"ad3ccb3438a02ac0968638fa6bfcd194addd0e6352d97235f1762c42a04e1eb7","lane":"rust-test","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":142,"stamp":"6dd7ee2fa63da31fd7442f7648a647d5","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
Ci-Attestation: {"at":1793810969,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"89034ad58ee31e6f4f7f96472ce0887950ee541c232aa87b42e0438dd874b4b6","lane":"cross","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":84,"stamp":"79ed599d0bf6dd30a4cf9fe931077638","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
Ci-Attestation: {"at":1793810969,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"89034ad58ee31e6f4f7f96472ce0887950ee541c232aa87b42e0438dd874b4b6","lane":"cross","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":84,"stamp":"437df2674667fc47a9ff02d4de5df647","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
Ci-Attestation: {"at":1793810969,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"89034ad58ee31e6f4f7f96472ce0887950ee541c232aa87b42e0438dd874b4b6","lane":"cross","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":84,"stamp":"790b5f7a391670abd05ef0dc52e65b57","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
Ci-Attestation: {"at":1793810969,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"89034ad58ee31e6f4f7f96472ce0887950ee541c232aa87b42e0438dd874b4b6","lane":"cross","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":84,"stamp":"8e47c826caa16acf6326bffa25dbc489","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
Ci-Attestation: {"at":1793810969,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"b9f7eb92939f575cf174379ee1017a99ce1b9f7454e4513da247fd7dd0648bb5","lane":"tier2-linux","parents":["817e4d9afbf5067cad0552c107e654c5f04a4fa0"],"secs":2198,"stamp":"ee204655a5f902de5bbba781e67aa299","tree":"6ad2c637b4895e52e61ea1c2285eb74feadf04d1","v":1,"via":"run"}
@rdoupe
rdoupe force-pushed the fix/bug-ep-makeshaderstring-leaks-it-602 branch from 02e51c3 to 72ba354 Compare November 4, 2026 16:49
@rdoupe
rdoupe marked this pull request as ready for review November 4, 2026 17:10
@rdoupe
rdoupe requested a review from zackees as a code owner November 4, 2026 17:10
@rdoupe
rdoupe added this pull request to the merge queue Nov 4, 2026
@rdoupe

rdoupe commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

Handed off to the coordinator

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 4, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Ready to merge in obs-rust Multiview Nov 4, 2026
@zackees
zackees added this pull request to the merge queue Nov 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 4, 2026
@zackees

zackees commented Nov 4, 2026

Copy link
Copy Markdown
Member

Continuing the handed-off PR under maintainer direction: investigating merge-queue run 41928113205 in an isolated worktree. Current master extracted private effect-parser helpers into effect-parser-funcs.c.h; this test target omits that source. Reproducing the complete linker diagnostics locally before an additive build-definition fix. Existing commits and C test assertions will be preserved.

Fix the Tier 2 merge-queue link failure for #3626 after #3627 extracted six private parser helpers. Compile their source into the standalone parser test, as sibling targets do; preserve symbol visibility and every existing C assertion.
@zackees

zackees commented Nov 4, 2026

Copy link
Copy Markdown
Member

Fixed the merge-queue Tier 2 link failure additively in 587382a, after merging master at 167da60 in 2feb30d. The original PR commits remain ancestors; no rebase or force-push.

Root cause: #3627 extracted private parser helpers into libobs/graphics/effect-parser-funcs.c.h. The standalone shader-call test compiles the parser but omitted that source. Sibling parser targets already include it. This is unrelated to the conflicting params port #3621.

The one-line fix adds that source to test_effect_parser_shader_call in test/cmocka/build/test-graph.json. No C test source, production behavior, public header, or symbol visibility changes.

Local RED on 2feb30d, using the repository's container harness:

OBS_TIER2_STAGE=build uv run --no-project rust/tools/linux-validate/run.py

Exit 1. The full /build/tree.build.log (the CI error filter hides these lines) reports:

FAILED: [code=1] test/cmocka/test_effect_parser_shader_call
effect-parser.c.h:430: undefined reference to `ep_getsampler'
effect-parser.c.h:483: undefined reference to `ep_getstruct'
effect-parser.c.h:644: undefined reference to `ep_getparam_strref'
effect-parser.c.h:652: undefined reference to `ep_getfunc_strref'
effect-parser.c.h:556: undefined reference to `ep_getstruct'
effect-parser.c.h:59: undefined reference to `ep_check_for_keyword'
effect-parser.c.h:65: undefined reference to `ep_check_for_keyword'
effect-parser.c.h:71: undefined reference to `ep_check_for_keyword'
effect-parser.c.h:112: undefined reference to `ep_parse_function'
collect2: error: ld returned 1 exit status

Local GREEN: the same full build command exited 0 after the one-line fix:

[20/23] Building C object test/cmocka/CMakeFiles/test_effect_parser_shader_call.dir/native-tests/test_effect_parser_shader_call/libobs/graphics/effect-parser-funcs.c.h.c.o
[22/23] Linking C executable test/cmocka/test_effect_parser_shader_call
== libobs exported symbols, C vs Rust
IDENTICAL (1767 symbols)

Then, in a fresh invocation of the same ci/docker_task.py container/volume harness, ran the actual unchanged test against both libraries:

LD_LIBRARY_PATH=/build/tree/libobs-c-reference ctest --test-dir /build/tree -V -R '^test_effect_parser_shader_call$'
LD_LIBRARY_PATH=/build/tree/libobs ctest --test-dir /build/tree -V -R '^test_effect_parser_shader_call$'
OFF: [  PASSED  ] 3 test(s).
100% tests passed, 0 tests failed out of 1
Total Test time (real) = 0.07 sec
ON: [  PASSED  ] 3 test(s).
100% tests passed, 0 tests failed out of 1
Total Test time (real) = 0.05 sec

Repository configuration checks:

PYTHONPATH=ci uv run --no-project -m unittest ci.test_build_groups ci.test_native_test_graph_slices ci.test_cmocka_windows_diagnostics ci.test_cmocka_rust_static_guard

17 tests, OK. git diff --check passed. No native platform implementation changed, so no native-coverage opt-in label applies; existing labels were preserved. Watching PR CI and then queueing through the required merge queue.

@zackees
zackees added this pull request to the merge queue Nov 4, 2026
Merged via the queue into master with commit 96008af Nov 4, 2026
42 checks passed
@zackees
zackees deleted the fix/bug-ep-makeshaderstring-leaks-it-602 branch November 4, 2026 23:32
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Ready to merge to Done in obs-rust Multiview Nov 5, 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.

bug: effect parser: an unknown pass function leaks and breaks the next shader

2 participants