Skip to content

Fix a few vertex buffer related issues - #13732

Open
notr1ch wants to merge 2 commits into
obsproject:masterfrom
notr1ch:r1ch/d3d-vertex-fixes
Open

Fix a few vertex buffer related issues#13732
notr1ch wants to merge 2 commits into
obsproject:masterfrom
notr1ch:r1ch/d3d-vertex-fixes

Conversation

@notr1ch

@notr1ch notr1ch commented Jul 31, 2026

Copy link
Copy Markdown
Member

Description

Crash reports indicated something was crashing in LoadVertexBufferData. While I was unable to reproduce a crash, I did notice some dangling pointers if vertex buffers, index buffers or vertex shaders were freed while rendering was still active. Worse, the code assumed that every draw call would have vertex positions, which is not true for the triangles used when rendering textures for GPU conversion and async sources. Those would end up using whatever vertex buffer was last loaded into buffer list, which if since-freed could also trigger a use-after-free crash.

I also noticed that we were inconsistent in our use of gs_load_indexbuffer - many places neglected to call it before drawing, causing it to use whatever the last draw caller set. Currently there's no direct code in OBS that ever calls this with a non-NULL value, but as this is exported to the API we should always assume it can be changed between draw calls.

Motivation and Context

Code correctness and hopefully crash fixes.

How Has This Been Tested?

Basic run of OBS with async texture sources, no obvious regression spotted. Unable to reproduce the crashing.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

notr1ch added 2 commits July 30, 2026 22:03
Crash reports indicated numerous crashes in LoadVertexBufferData.
Looking through the code revealed that the device's curVertexBuffer /
curVertexShader / curIndexBuffer variables were not cleared when the
corresponding object was destroyed, leaving them pointing to dangling
memory. This also affected the device rebuild path in reverse - cur was
cleared, last was not.

The buffer list was also assuming that every vertex shader has vertex
positions, which is not true for the triangles drawn by async sources and
GPU conversion textures. As those draws never load a vertex buffer, they
ended up using whatever was left by the previous draw call - incorrect
but harmless if the buffer is valid, use-after-free if it is not.
We load vertex and index buffers inconsistently between libobs and the
frontend - some draws load a vertex buffer without an index buffer and
some draws load neither. This causes the device to use whatever the
previous draw call left behind, which is not a good practice.

While nothing in OBS itself binds an index buffer today, the graphics
API is exposed to plugins and any source render callback could leave
one bound.
@notr1ch notr1ch added kind/bug Categorizes issue or PR as related to a bug. platform/windows Categorizes issue or PR as affecting Windows specifically labels Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. platform/windows Categorizes issue or PR as affecting Windows specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant