Browse Source

Fixed filedata not being cleaned up when love.image.newImageData(filepath) fails

Alex Szpakowski 12 years ago
parent
commit
9e9eb42f1d
3 changed files with 11 additions and 10 deletions
  1. 11 3
      src/modules/image/devil/ImageData.cpp
  2. 0 4
      src/scripts/graphics.lua
  3. 0 3
      src/scripts/graphics.lua.h

+ 11 - 3
src/modules/image/devil/ImageData.cpp

@@ -53,7 +53,15 @@ ImageData::ImageData(Data *data)
 ImageData::ImageData(filesystem::File *file)
 {
 	Data *data = file->read();
-	load(data);
+	try
+	{
+		load(data);
+	}
+	catch (love::Exception &)
+	{
+		data->release();
+		throw;
+	}
 	data->release();
 }
 
@@ -124,10 +132,10 @@ void ImageData::load(Data *data)
 
 		create(width, height, ilGetData());
 	}
-	catch(std::exception &)
+	catch(std::exception &e)
 	{
 		ilDeleteImages(1, &image);
-		throw;
+		throw love::Exception("%s", e.what());
 	}
 
 	ilDeleteImages(1, &image);

+ 0 - 4
src/scripts/graphics.lua

@@ -1361,8 +1361,6 @@ void main() {
 	end
 
 	function love.graphics._shaderCodeToGLSL(vertexcode, pixelcode)
-		local vertexarg, pixelarg = vertexcode, pixelcode
-
 		if vertexcode then
 			local s = vertexcode:gsub("\r\n\t", " ")
 			s = s:gsub("(%w+)(%s+)%(", "%1(")
@@ -1373,7 +1371,6 @@ void main() {
 				vertexcode = nil -- first argument doesn't contain vertex shader code
 			end
 		end
-
 		if pixelcode then
 			local s = pixelcode:gsub("\r\n\t", " ")
 			s = s:gsub("(%w+)(%s+)%(", "%1(")
@@ -1388,7 +1385,6 @@ void main() {
 		if vertexcode then
 			vertexcode = createVertexCode(vertexcode)
 		end
-
 		if pixelcode then
 			pixelcode = createPixelCode(pixelcode)
 		end

+ 0 - 3
src/scripts/graphics.lua.h

@@ -6388,9 +6388,6 @@ const unsigned char graphics_lua[] =
 	0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x5f, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x54, 
 	0x6f, 0x47, 0x4c, 0x53, 0x4c, 0x28, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 
 	0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x29, 0x0a,
-	0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x61, 0x72, 0x67, 0x2c, 
-	0x20, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x61, 0x72, 0x67, 0x20, 0x3d, 0x20, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 
-	0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x0a,
 	0x09, 0x09, 0x69, 0x66, 0x20, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x74, 0x68, 
 	0x65, 0x6e, 0x0a,
 	0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x76, 0x65, 0x72, 0x74, 0x65,