diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libjin/audio/sdl/source.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/libjin/audio/sdl/source.cpp b/src/libjin/audio/sdl/source.cpp index bfe090b..69c0670 100644 --- a/src/libjin/audio/sdl/source.cpp +++ b/src/libjin/audio/sdl/source.cpp @@ -57,7 +57,13 @@ namespace audio SDLSource* SDLSource::createSource(SourceType format, const char* file) { - std::ifstream fs(file, std::ios::binary); + std::ifstream fs; + fs.open(file, std::ios::binary); + if (!fs.is_open()) + { + fs.close(); + return nullptr; + } fs.seekg(0,std::ios::end); int size = fs.tellg(); fs.seekg(0, std::ios::beg); @@ -74,20 +80,16 @@ namespace audio if (mem == nullptr) return nullptr; SDLSource* source = new SDLSource(); - memset(&source->status, 0, sizeof(status)); - memset(&source->raw, 0, sizeof(raw)); +#define read(FMT) case FMT : source->load##FMT(mem, size); break try { switch (format) { - case WAV: - source->loadWAV(mem, size); - break; - case OGG: - source->loadOGG(mem, size); - break; + read(OGG); + read(WAV); } } +#undef read catch (SourceException& exp) { delete source; @@ -98,6 +100,8 @@ namespace audio SDLSource::SDLSource() { + memset(&status, 0, sizeof(status)); + memset(&raw, 0, sizeof(raw)); } SDLSource::~SDLSource() |