From 4cfa640e6985849ff107591b9da144995205fcc9 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 24 May 2017 16:41:47 -0400 Subject: [PATCH] Initialize the SDL audio subsystem if necessary. SDL_OpenAudio() did this for us (legacy 1.2 behavior), but SDL_OpenAudioDevice() doesn't, leaving us to manage it. Fixes Bugzilla #3596. --- mixer.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mixer.c b/mixer.c index 104b0b28..9d255690 100644 --- a/mixer.c +++ b/mixer.c @@ -25,9 +25,7 @@ #include #include -#include "SDL_mutex.h" -#include "SDL_endian.h" -#include "SDL_timer.h" +#include "SDL.h" #include "SDL_mixer.h" #include "mixer.h" @@ -435,6 +433,15 @@ int Mix_OpenAudioDevice(int frequency, Uint16 format, int nchannels, int chunksi int i; SDL_AudioSpec desired; + /* This used to call SDL_OpenAudio(), which initializes the audio + subsystem if necessary. Since SDL_OpenAudioDevice() doesn't, + we have to handle this case here. */ + if (!SDL_WasInit(SDL_INIT_AUDIO)) { + if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { + return -1; + } + } + /* If the mixer is already opened, increment open count */ if ( audio_opened ) { if ( format == mixer.format && nchannels == mixer.channels ) {