From e9c7607a4b9e31528efb384ab5fb7c03926f7f5e Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 27 Apr 2018 00:04:04 -0700 Subject: [PATCH] Added init check --- AudioPlayer.cpp | 85 +++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/AudioPlayer.cpp b/AudioPlayer.cpp index 6f4010d..bfbc2c1 100644 --- a/AudioPlayer.cpp +++ b/AudioPlayer.cpp @@ -6,6 +6,7 @@ #include #define NUM_SOUNDS 10 static SDL_AudioSpec fmt; +static bool initiated = false; AudioPlayer::AudioPlayer(void) { @@ -19,6 +20,7 @@ AudioPlayer::~AudioPlayer(void) void AudioPlayer::init() { + initiated = true; extern void mixaudio(void *unused, Uint8 *stream, int len); fmt.freq = 22050; fmt.format = AUDIO_S16; @@ -59,46 +61,53 @@ void mixaudio(void *unused, Uint8 *stream, int len) void AudioPlayer::PlaySound(std::string fileString) { - char *file = new char[fileString.length() + 1]; - strcpy(file, fileString.c_str()); - + if(initiated) + { + char *file = new char[fileString.length() + 1]; + strcpy(file, fileString.c_str()); + - int index; - SDL_AudioSpec wave; - Uint8 *data; - Uint32 dlen; - SDL_AudioCVT cvt; + int index; + SDL_AudioSpec wave; + Uint8 *data; + Uint32 dlen; + SDL_AudioCVT cvt; - /* Look for an empty (or finished) sound slot */ - for ( index=0; index