fmod: return NullAudioSound if file does not exist

This matches the OpenAL behaviour, and is needed to fix the unit tests on macOS.
This commit is contained in:
rdb 2018-07-08 21:49:37 +02:00
parent c6ed4e1836
commit abe20fc489
3 changed files with 22 additions and 22 deletions

View File

@ -419,15 +419,19 @@ get_sound(const std::string &file_name, bool positional, int) {
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
vfs->resolve_filename(path, get_model_path());
// Build a new AudioSound from the audio data.
PT(AudioSound) audioSound;
PT(FmodAudioSound) fmodAudioSound = new FmodAudioSound(this, path, positional);
// Locate the file on disk.
path.set_binary();
PT(VirtualFile) file = vfs->get_file(path);
if (file != nullptr) {
// Build a new AudioSound from the audio data.
PT(FmodAudioSound) sound = new FmodAudioSound(this, file, positional);
_all_sounds.insert(fmodAudioSound);
audioSound = fmodAudioSound;
return audioSound;
_all_sounds.insert(sound);
return sound;
} else {
audio_error("createSound(" << path << "): File not found.");
return get_null_sound();
}
}
/**

View File

@ -39,9 +39,10 @@ TypeHandle FmodAudioSound::_type_handle;
*/
FmodAudioSound::
FmodAudioSound(AudioManager *manager, Filename file_name, bool positional) {
FmodAudioSound(AudioManager *manager, VirtualFile *file, bool positional) {
ReMutexHolder holder(FmodAudioManager::_lock);
audio_debug("FmodAudioSound::FmodAudioSound() Creating new sound, filename: " << file_name );
audio_debug("FmodAudioSound::FmodAudioSound() Creating new sound, filename: "
<< file->get_original_filename());
_active = manager->get_active();
_paused = false;
@ -77,20 +78,14 @@ FmodAudioSound(AudioManager *manager, Filename file_name, bool positional) {
_manager = fmanager;
_channel = 0;
_file_name = file_name;
_file_name = file->get_original_filename();
_file_name.set_binary();
// Get the Speaker Mode [Important for later on.]
result = _manager->_system->getSpeakerMode( &_speakermode );
fmod_audio_errcheck("_system->getSpeakerMode()", result);
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
PT(VirtualFile) file = vfs->get_file(_file_name);
if (file == nullptr) {
// File not found. We will display the appropriate error message below.
result = FMOD_ERR_FILE_NOTFOUND;
} else {
{
bool preload = (fmod_audio_preload_threshold < 0) || (file->get_file_size() < fmod_audio_preload_threshold);
int flags = FMOD_SOFTWARE;
flags |= positional ? FMOD_3D : FMOD_2D;
@ -149,7 +144,7 @@ FmodAudioSound(AudioManager *manager, Filename file_name, bool positional) {
#if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS)
// Otherwise, if the Panda threading system is compiled in, we can
// assign callbacks to read the file through the VFS.
name_or_data = (const char *)file.p();
name_or_data = (const char *)file;
sound_info.length = (unsigned int)info.get_size();
sound_info.useropen = open_callback;
sound_info.userclose = close_callback;

View File

@ -70,10 +70,11 @@
#include <fmod.hpp>
#include <fmod_errors.h>
class EXPCL_FMOD_AUDIO FmodAudioSound : public AudioSound {
public:
class VirtualFile;
FmodAudioSound(AudioManager *manager, Filename fn, bool positional );
class EXPCL_FMOD_AUDIO FmodAudioSound : public AudioSound {
public:
FmodAudioSound(AudioManager *manager, VirtualFile *file, bool positional);
~FmodAudioSound();
// For best compatibility, set the loop_count, start_time, volume, and