mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
No more crashes when there is no memory for newImageData (issue #209)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user