From 3e829110a40f811a0216e3bc648bc7f2485f3b4d Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 28 Jan 2016 11:41:18 +0100 Subject: Handle sndffile open failure. --- src/audiocachefile.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/audiocachefile.cc b/src/audiocachefile.cc index 942afd3..039a46d 100644 --- a/src/audiocachefile.cc +++ b/src/audiocachefile.cc @@ -30,16 +30,21 @@ #include +#include + #include "audiocache.h" AudioCacheFile::AudioCacheFile(const std::string& filename) : filename(filename) { + std::memset(&sf_info, 0, sizeof(SF_INFO)); + fh = sf_open(filename.c_str(), SFM_READ, &sf_info); if(!fh) { ERR(audiofile,"SNDFILE Error (%s): %s\n", filename.c_str(), sf_strerror(fh)); + return; } if(sf_info.frames == 0) @@ -75,7 +80,11 @@ size_t AudioCacheFile::getChannelCount() void AudioCacheFile::readChunk(const CacheChannels& channels, size_t pos, size_t num_samples) { - assert(fh != nullptr); // File handle must never be nullptr + //assert(fh != nullptr); // File handle must never be nullptr + if(!fh) + { + return; + } if((int)pos > sf_info.frames) { -- cgit v1.2.3