Skip to content

libobs/graphics: Check the graphics context in gs_matrix_scale3f (#2518) - #2520

Merged
zackees merged 3 commits into
masterfrom
fix/2518-gs-valid
Oct 26, 2026
Merged

zackees merged 3 commits into
masterfrom
fix/2518-gs-valid

Conversation

@vpacher

@vpacher vpacher commented Oct 26, 2026

Copy link
Copy Markdown
Member

Fixes #2518

Two small fixes in libobs/graphics/graphics.c.h, before the port of the graphics state stacks (#2517):

  • gs_matrix_scale3f read thread_graphics without gs_valid, so a call without a graphics context on the thread (a plugin or a script; obslua and obspython include all of graphics.h) crashed OBS on a NULL dereference. It now checks with gs_valid first, as the other thirteen gs_matrix_* functions do: it logs gs_matrix_scale3f: called while not in a graphics context (LOG_DEBUG) and returns.
  • gs_reset_blend_state checked with gs_valid("gs_preprocessor_name"), so its log line named the wrong function (since d242004, 2015). It now names itself.

Both are unchanged in upstream OBS master.

RED → GREEN

  1. RED 526d49662: test_graphics_no_context (new) calls the fourteen gs_matrix_* functions, gs_viewport_push/pop, gs_blend_state_push/pop and gs_reset_blend_state without a graphics context, with a log handler, and expects each one to return and log its own name. Fails on both libobs builds: gs_matrix_scale3f crashes (segmentation fault), gs_reset_blend_state logs gs_preprocessor_name.
  2. GREEN 55e555248: the two changes.

Tier 2 (Linux x86_64, Debian 13)

  • Lint lane (ci/local_gate.py --lane lint) passes.
  • test_graphics_no_context, test_texture_render, test_sprite_flip_render and test_scene_rotated_scale_filter pass on the hybrid libobs and on libobs-c-reference (4/4 each).

Checklist

  • Base is master
  • 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
  • User-visible change: a plugin or script that calls gs_matrix_scale3f outside a graphics context no longer crashes OBS
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes: not applicable
  • Intentional differences from C: not applicable

🤖 Generated with Claude Code

vpacher and others added 2 commits October 26, 2026 19:44
… (RED, #2518)

test_graphics_no_context calls the fourteen gs_matrix_* functions and
gs_viewport_push/pop, gs_blend_state_push/pop and gs_reset_blend_state
without a graphics context on the thread, with a log handler. Each one is
expected to return and log "<name>: called while not in a graphics
context" (gs_valid, LOG_DEBUG), as thirteen of the matrix functions and
the stack functions do.

RED: gs_matrix_scale3f reads thread_graphics without gs_valid and
dereferences NULL (the test crashes); gs_reset_blend_state logs the name
gs_preprocessor_name.

Refs #2518

Co-Authored-By: Claude Opus 5.5 <[email protected]>
gs_matrix_scale3f read thread_graphics without gs_valid, so a call
without a graphics context on the thread (a plugin or a script) crashed
OBS on a NULL dereference. It now checks with gs_valid first, as the
other thirteen gs_matrix_* functions do: it logs "gs_matrix_scale3f:
called while not in a graphics context" (LOG_DEBUG) and returns.

gs_reset_blend_state checked with gs_valid("gs_preprocessor_name"), so
its log line named the wrong function (since d242004, 2015); it now
names itself.

Both are unchanged in upstream OBS master.

GREEN: test_graphics_no_context passes on the C reference and the
hybrid libobs.

Fixes #2518

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed: both fixes are correct and minimal. RED crashes/mislogs on both libobs builds, GREEN fixes it, and the new test covers all fourteen gs_matrix_* functions plus the viewport and blend stacks. I pushed the missing features-ledger line under Scripting. Queuing once CI is green.

@zackees
zackees enabled auto-merge October 26, 2026 18:52
@zackees
zackees added this pull request to the merge queue Oct 26, 2026
Merged via the queue into master with commit d9e9251 Oct 26, 2026
36 checks passed
@zackees
zackees deleted the fix/2518-gs-valid branch October 26, 2026 19:14
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In review to Done in obs-rust Multiview Oct 26, 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: libobs/graphics: gs_matrix_scale3f crashes without a graphics context (and gs_reset_blend_state logs the wrong name)

2 participants