]> git.tdb.fi Git - libs/gui.git/commitdiff
Detect loading errors from DevIL
authorMikko Rasa <tdb@tdb.fi>
Mon, 7 Oct 2013 18:13:40 +0000 (21:13 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 7 Oct 2013 18:13:40 +0000 (21:13 +0300)
source/graphics/devil/devilloader.cpp

index 88beb04802d47025c2995d886d227d3d6dc3d78d..cb6a1b6251764a29fd90cc7c0a36c3e509e9a991 100644 (file)
@@ -1,4 +1,5 @@
 #include <algorithm>
+#include <msp/strings/format.h>
 #include <IL/il.h>
 #include "devilloader.h"
 
@@ -53,6 +54,20 @@ int tell(void *handle)
        return reinterpret_cast<Msp::IO::Seekable *>(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))
        {