diff --git a/changes.txt b/changes.txt index 6aaecfead..0e69c0a09 100644 --- a/changes.txt +++ b/changes.txt @@ -11,6 +11,7 @@ LOVE 0.7.2 [Game Slave] * Fixed files loaded by libmodplug being too loud. * Fixed paths with periods in them not working. * Fixed love.graphics.getBlendMode not detecting subtractive and multiplicative blend modes. + * Fixed crash when there was no memory available for newImageData(w, h). * Updated PhysicsFS version to 2.0.2 on Windows * Updated OpenAL Soft version to 1.13 on Windows diff --git a/src/modules/image/devil/ImageData.cpp b/src/modules/image/devil/ImageData.cpp index 1f0ca891d..5d0742df7 100644 --- a/src/modules/image/devil/ImageData.cpp +++ b/src/modules/image/devil/ImageData.cpp @@ -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); diff --git a/src/modules/image/wrap_Image.cpp b/src/modules/image/wrap_Image.cpp index a63eebbbe..560c6df74 100644 --- a/src/modules/image/wrap_Image.cpp +++ b/src/modules/image/wrap_Image.cpp @@ -43,7 +43,12 @@ namespace image { int w = luaL_checkint(L, 1); int h = luaL_checkint(L, 2); - ImageData * t = instance->newImageData(w, h); + ImageData * t = 0; + try { + t = instance->newImageData(w, h); + } catch (love::Exception & e) { + return luaL_error(L, e.what()); + } luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void*)t); return 1; }