From f970bc32292dd669fdc1427aaa4f3f36cd10fbce Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Mon, 19 Feb 2018 21:27:28 -0700 Subject: [PATCH] openal: Don't return OpenALAudioSounds that fail to initialize Also don't register them in _all_sounds, where they won't remove themselves due to having already called cleanup() on themselves. Additionally stops a sound in a cleaned-up state from being passed to the app and played. --- panda/src/audiotraits/openalAudioManager.cxx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/panda/src/audiotraits/openalAudioManager.cxx b/panda/src/audiotraits/openalAudioManager.cxx index 8d38eeec49..cbdaadbfa1 100644 --- a/panda/src/audiotraits/openalAudioManager.cxx +++ b/panda/src/audiotraits/openalAudioManager.cxx @@ -471,6 +471,12 @@ get_sound(MovieAudio *sound, bool positional, int mode) { PT(OpenALAudioSound) oas = new OpenALAudioSound(this, sound, positional, mode); + if(!oas->_manager) { + // The sound cleaned itself up immediately. It pretty clearly didn't like + // something, so we should just return a null sound instead. + return get_null_sound(); + } + _all_sounds.insert(oas); PT(AudioSound) res = (AudioSound*)(OpenALAudioSound*)oas; return res; @@ -500,6 +506,12 @@ get_sound(const string &file_name, bool positional, int mode) { PT(OpenALAudioSound) oas = new OpenALAudioSound(this, mva, positional, mode); + if(!oas->_manager) { + // The sound cleaned itself up immediately. It pretty clearly didn't like + // something, so we should just return a null sound instead. + return get_null_sound(); + } + _all_sounds.insert(oas); PT(AudioSound) res = (AudioSound*)(OpenALAudioSound*)oas; return res;