瀏覽代碼

correctly return NullAudioSound if unable to load file

David Rose 19 年之前
父節點
當前提交
b26fa4b410
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      panda/src/audiotraits/milesAudioManager.cxx

+ 6 - 1
panda/src/audiotraits/milesAudioManager.cxx

@@ -275,6 +275,7 @@ load(Filename file_name) {
   } else if ((int)sd->_raw_data.size() >= miles_audio_expand_mp3_threshold) {
     audio_debug(sd->_basename << " is too large to expand in-memory.");
   } else {
+    audio_debug(sd->_basename << " will be expanded in-memory.");
     expand_to_wav = true;
   }
 
@@ -376,9 +377,13 @@ get_sound(const string& file_name, bool) {
     bool inserted = _sounds_on_loan.insert(milesAudioSound).second;
     nassertr(inserted, milesAudioSound.p());
     audioSound=milesAudioSound;
+
+    _hasMidiSounds |= (file_name.find(".mid")!=string::npos);
+  } else {
+    // Couldn't load the file; just return a NullAudioSound.
+    audioSound = new NullAudioSound;
   }
 
-  _hasMidiSounds |= (file_name.find(".mid")!=string::npos);
   audio_debug("  returning 0x" << (void*)audioSound);
   assert(is_valid());
   return audioSound;