From: Mikko Rasa Date: Mon, 7 Oct 2013 18:13:40 +0000 (+0300) Subject: Detect loading errors from DevIL X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=88814cd5cde0bddb56d299b2edbc48e8351a4311;p=libs%2Fgui.git Detect loading errors from DevIL --- diff --git a/source/graphics/devil/devilloader.cpp b/source/graphics/devil/devilloader.cpp index 88beb04..cb6a1b6 100644 --- a/source/graphics/devil/devilloader.cpp +++ b/source/graphics/devil/devilloader.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "devilloader.h" @@ -53,6 +54,20 @@ int tell(void *handle) return reinterpret_cast(handle)->tell(); } +std::string error_string(ILenum err) +{ + switch(err) + { + case IL_FORMAT_NOT_SUPPORTED: return "Format not supported"; + case IL_INTERNAL_ERROR: return "DevIL internal error"; + case IL_INVALID_FILE_HEADER: return "Invalid file header"; + case IL_FILE_READ_ERROR: return "File read error"; + case IL_LIB_PNG_ERROR: return "LibPNG error"; + case IL_LIB_JPEG_ERROR: return "LibJPEG error"; + default: return Msp::format("Unknown error (%04X)", err); + } +} + } // namespace @@ -92,7 +107,10 @@ void DevilLoader::load(Image::Data &data) { ilSetRead(0, 0, eof, get, read, seek, tell); ilBindImage(id); - ilLoadF(IL_TYPE_UNKNOWN, &io); + + ilGetError(); + if(!ilLoadF(IL_TYPE_UNKNOWN, &io)) + throw bad_image_data(error_string(ilGetError())); switch(ilGetInteger(IL_IMAGE_FORMAT)) {