No more crashes when there is no memory for newImageData (issue #209)

This commit is contained in:
Bart van Strien
2011-04-07 19:22:55 +02:00
parent 529530c198
commit d55941f7fa
3 changed files with 29 additions and 2 deletions
+22 -1
View File
@@ -88,7 +88,28 @@ namespace devil
// Bind the image.
ilBindImage(image);
ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, 0);
bool success = ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, 0);
int err = ilGetError();
if (err != IL_NO_ERROR){
switch (err) {
case IL_ILLEGAL_OPERATION:
throw love::Exception("Error: Illegal operation");
break;
case IL_INVALID_PARAM:
throw love::Exception("Error: invalid parameters");
break;
case IL_OUT_OF_MEMORY:
throw love::Exception("Error: out of memory");
break;
default:
throw love::Exception("Error: unknown error");
break;
}
}
if(!success) {
throw love::Exception("Could not decode image data.");
}
// Set to black.
memset((void*)ilGetData(), 0, width*height*4);