libobs: Add stop_audio function, change shutdown order

This fixes a crash that could occur during freeing of sources, as the
audio subsystem was destroyed before sources were released. If a source
had monitoring enabled, it would try to lock a mutex that has been
destroyed, resulting in a crash.

Freeing audio after obs_free_data was also not a solution, as the main
view is freed in obs_free_data, and the audio subsystem is still running
and trying to lock the main view channel mutex which has been freed.

This seems to be the best middle ground, making sure the audio subsystem
is stopped so it no longer tries to access the main view channel, then
freed after obs_free_data.

Fixes https://github.com/obsproject/obs-studio/issues/4409
master
Richard Stanway 2021-05-07 01:52:52 +02:00
parent 8b50ad5e2a
commit 3dbfa4919a
1 changed files with 12 additions and 1 deletions

View File

@ -597,6 +597,16 @@ static bool obs_init_audio(struct audio_output_info *ai)
return false;
}
static void stop_audio(void)
{
struct obs_core_audio *audio = &obs->audio;
if (audio->audio) {
audio_output_close(audio->audio);
audio->audio = NULL;
}
}
static void obs_free_audio(void)
{
struct obs_core_audio *audio = &obs->audio;
@ -1026,6 +1036,7 @@ void obs_shutdown(void)
da_free(obs->transition_types);
stop_video();
stop_audio();
stop_hotkeys();
module = obs->first_module;
@ -1036,8 +1047,8 @@ void obs_shutdown(void)
}
obs->first_module = NULL;
obs_free_audio();
obs_free_data();
obs_free_audio();
obs_free_video();
obs_free_hotkeys();
obs_free_graphics();