From 88814cd5cde0bddb56d299b2edbc48e8351a4311 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 7 Oct 2013 21:13:40 +0300 Subject: [PATCH] Detect loading errors from DevIL --- source/graphics/devil/devilloader.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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)) { -- 2.45.2