From 444e2ffb2d2f2c9930df41d2527631469c0511d1 Mon Sep 17 00:00:00 2001 From: Automatic Release Builder Date: Thu, 15 Oct 2020 17:00:30 +0100 Subject: [PATCH] Sound: readWAV: avoid common exceptions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid exceptions for the common ‘file not found’ case, and instead return false / nullptr. Erik says it’s fine. --- simgear/sound/readwav.cxx | 9 ++++++--- simgear/sound/soundmgr_openal.cxx | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/simgear/sound/readwav.cxx b/simgear/sound/readwav.cxx index ffb0da0d..c0724cce 100644 --- a/simgear/sound/readwav.cxx +++ b/simgear/sound/readwav.cxx @@ -380,7 +380,8 @@ namespace simgear ALvoid* loadWAVFromFile(const SGPath& path, unsigned int& format, ALsizei& size, ALfloat& freqf, unsigned int& block_align) { if (!path.exists()) { - throw sg_io_exception("loadWAVFromFile: file not found", path); + SG_LOG(SG_IO, SG_DEV_ALERT, "loadWAVFromFile: file not found:" << path); + return nullptr; } Buffer b; @@ -395,13 +396,15 @@ ALvoid* loadWAVFromFile(const SGPath& path, unsigned int& format, ALsizei& size, fd = gzopen(ps.c_str(), "rb"); #endif if (!fd) { - throw sg_io_exception("loadWAVFromFile: unable to open file", path); + SG_LOG(SG_IO, SG_DEV_ALERT, "loadWAVFromFile: unable to open file:" << path); + return nullptr; } try { loadWavFile(fd, &b); } catch (sg_exception& e) { - throw sg_io_exception(e.getFormattedMessage() + "\nfor: " + path.str()); + SG_LOG(SG_IO, SG_DEV_ALERT, "loadWAVFromFile:" << e.getFormattedMessage() << "\nfor: " << path); + return nullptr; } ALvoid* data = b.data; diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index a64f9c6d..51855dbb 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -813,13 +813,14 @@ bool SGSoundMgr::load( const std::string &samplepath, auto data = simgear::loadWAVFromFile(samplepath, format, size, freqf, blocksz); freq = (ALsizei)freqf; - if (data == nullptr) { - throw sg_io_exception("Failed to load wav file", sg_location(samplepath)); + if (!data) { + return false; } if (format == AL_FORMAT_STEREO8 || format == AL_FORMAT_STEREO16) { free(data); - throw sg_io_exception("Warning: STEREO files are not supported for 3D audio effects: " + samplepath); + SG_LOG(SG_IO, SG_DEV_ALERT, "Warning: STEREO files are not supported for 3D audio effects: " << samplepath); + return false; } *dbuf = (void *)data;