Browse Source

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.
Sam Edwards 7 years ago
parent
commit
f970bc3229
1 changed files with 12 additions and 0 deletions
  1. 12 0
      panda/src/audiotraits/openalAudioManager.cxx

+ 12 - 0
panda/src/audiotraits/openalAudioManager.cxx

@@ -471,6 +471,12 @@ get_sound(MovieAudio *sound, bool positional, int mode) {
   PT(OpenALAudioSound) oas =
   PT(OpenALAudioSound) oas =
     new OpenALAudioSound(this, sound, positional, mode);
     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);
   _all_sounds.insert(oas);
   PT(AudioSound) res = (AudioSound*)(OpenALAudioSound*)oas;
   PT(AudioSound) res = (AudioSound*)(OpenALAudioSound*)oas;
   return res;
   return res;
@@ -500,6 +506,12 @@ get_sound(const string &file_name, bool positional, int mode) {
   PT(OpenALAudioSound) oas =
   PT(OpenALAudioSound) oas =
     new OpenALAudioSound(this, mva, positional, mode);
     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);
   _all_sounds.insert(oas);
   PT(AudioSound) res = (AudioSound*)(OpenALAudioSound*)oas;
   PT(AudioSound) res = (AudioSound*)(OpenALAudioSound*)oas;
   return res;
   return res;