Skip to content

Fix crash on source resize while Replay Buffer is active (#166)#179

Open
romanrafael12 wants to merge 1 commit into
exeldro:masterfrom
romanrafael12:master
Open

Fix crash on source resize while Replay Buffer is active (#166)#179
romanrafael12 wants to merge 1 commit into
exeldro:masterfrom
romanrafael12:master

Conversation

@romanrafael12
Copy link
Copy Markdown

Hi exeldro,

I ran into the crash described in #166 and tracked down the cause.
This PR fixes it.

The problem

When a source's resolution changes while a Source Record filter has
the Replay Buffer enabled (for example, tabbing in/out of a window
capture), OBS crashes.

source_record_filter_tick() recreated the obs_view / video_output
by calling obs_view_remove() immediately on a size change — while the
encoder was still feeding from the old video_output and the replay
buffer output was still running. The encoder kept pulling frames from a
freed video_output, causing a use-after-free crash.

Three related issues:

  1. video_output destroyed while in useobs_view_remove() ran
    synchronously on a size change, even with outputs/encoder still active.
  2. encoder released while activeupdate_encoder() called
    obs_encoder_release() without checking obs_encoder_active() first
    (release_encoders() already does this check, so it was inconsistent).
  3. race on async restart — new outputs could start (reusing the
    encoder) while a previous output was still being force-stopped.

The fix

  • On a size change with active outputs, only set restart = true and
    defer recreation. video_output is recreated only once outputs are
    down and the encoder is idle.
  • update_encoder() no longer releases an active encoder, and re-points
    the encoder to the current video_output when reusing an idle one.
  • The output-start path waits until any previous encoder has fully wound
    down before starting new outputs.

44 lines changed; no behavior change for the normal start/stop path.

Testing

Tested on Windows with OBS 32.1.2. Ran 8 simultaneous Source Record
filters with Replay Buffer enabled for ~37 minutes — 100+ replay saves,
repeated scene switches and source resizes. No crashes, clean shutdown.
The same scenario reliably crashed before the patch.

Thanks for the plugin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant