Skip to content

Latest commit

 

History

History
68 lines (54 loc) · 3.42 KB

File metadata and controls

68 lines (54 loc) · 3.42 KB

WASAPI Audio Crash Fix Summary - Version 2

Problem

The crash was occurring because the WASAPI audio subsystem was still actively processing audio data from the browser source during OBS shutdown. This caused an access violation (c0000005) in copy_audio_data when it tried to access freed memory.

Root Cause

The browser source itself generates audio from web content (videos, audio elements, etc.). Even though the plugin doesn't directly handle audio, the browser source it creates is an audio-generating source that OBS's WASAPI system processes. The previous fix attempted to disconnect audio after creation, but the browser source was still initializing its audio components and registering with WASAPI.

Critical Fixes Implemented - Version 2

1. Disable Audio at Browser Source Creation

The most important fix is to completely disable audio in the browser source settings BEFORE creation:

// CRITICAL FIX: Completely disable audio in browser source to prevent WASAPI crashes
obs_data_set_bool(settings, "reroute_audio", false);
obs_data_set_bool(settings, "muted", true);  // Mute from creation
obs_data_set_int(settings, "audio_output_mode", 0);  // 0 = No audio output
obs_data_set_bool(settings, "monitor_audio", false);  // No audio monitoring
obs_data_set_bool(settings, "audio_output_to_stream", false);  // Don't output audio to stream
obs_data_set_bool(settings, "audio_output_to_desktop", false);  // Don't output audio to desktop

This prevents the browser source from ever initializing audio components that could crash during shutdown.

2. Post-Creation Audio Disconnection

After creating the browser source, we triple-ensure audio is disabled:

obs_source_set_muted(m_banner_source, true);
obs_source_set_volume(m_banner_source, 0.0f);
obs_source_set_monitoring_type(m_banner_source, OBS_MONITORING_TYPE_NONE);
obs_source_set_audio_active(m_banner_source, false);
obs_source_update(m_banner_source, settings);  // Force settings update

3. Enhanced Shutdown Sequence

During emergency shutdown, we now:

  • Navigate browser to about:blank to stop all media playback
  • Set browser shutdown flag to trigger CEF cleanup
  • Push empty audio frame to flush pending operations
  • Wait with extended synchronization for WASAPI threads

4. All Previous Fixes Still Apply

  • Source Protection Mutex
  • Signal Disconnection
  • Remove from ALL Scenes
  • Extended Synchronization (350ms+ total)
  • Memory Barrier
  • Null-Before-Release
  • Dedicated Cleanup Thread

Key Improvements in Version 2

  1. Prevention vs. Mitigation: Instead of trying to clean up audio after the fact, we prevent the browser source from ever initializing audio components
  2. Browser-Specific Cleanup: Navigate to blank page and set shutdown flag to stop media playback
  3. Comprehensive Settings: Use all available browser source audio settings to ensure complete disablement
  4. Applied to All Creation Paths: Updated all three locations where browser sources are created

Testing Instructions

  1. Install the updated plugin
  2. Add a browser source banner with video/audio content
  3. Let it play for a few seconds
  4. Exit OBS while content is playing
  5. OBS should shut down cleanly without crashes

Result

By disabling audio at the browser source creation level and adding browser-specific cleanup procedures, we prevent the WASAPI audio system from ever processing audio from our browser sources, eliminating the crash during shutdown.