Skip to content

Commit

Permalink
Initialize the SDL audio subsystem if necessary.
Browse files Browse the repository at this point in the history
SDL_OpenAudio() did this for us (legacy 1.2 behavior), but
SDL_OpenAudioDevice() doesn't, leaving us to manage it.

Fixes Bugzilla #3596.
  • Loading branch information
icculus committed May 24, 2017
1 parent 3be85c9 commit 4cfa640
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions mixer.c
Expand Up @@ -25,9 +25,7 @@
#include <stdlib.h>
#include <string.h>

#include "SDL_mutex.h"
#include "SDL_endian.h"
#include "SDL_timer.h"
#include "SDL.h"

#include "SDL_mixer.h"
#include "mixer.h"
Expand Down Expand Up @@ -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 ) {
Expand Down

0 comments on commit 4cfa640

Please sign in to comment.