Commits

Bart van Strien committed e6abd96

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

  • Participants
  • Parent commits bae4a59

Comments (0)

Files changed (3)

   * 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

src/modules/image/devil/ImageData.cpp

 		// 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);

src/modules/image/wrap_Image.cpp

 		{
 			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;
 		}