Anonymous avatar Anonymous committed b5b5663

Fixed crash on attempt to open non-existent file.

Comments (0)

Files changed (2)

src/modules/filesystem/physfs/File.cpp

 			return true;
 
 		// File must exist if read mode.
-		if((mode == READ))
-			if(!PHYSFS_exists(filename.c_str()))
-				throw love::Exception("Could not open file %s. Does not exist.", filename.c_str());
+		if((mode == READ) && !PHYSFS_exists(filename.c_str()))
+			throw love::Exception("Could not open file %s. Does not exist.", filename.c_str());
 
 		// Check whether the write directory is set.
-		if((mode == APPEND || mode == WRITE) && (PHYSFS_getWriteDir() == 0))
-			if(!hack_setupWriteDirectory())
-				throw love::Exception("Could not set write directory.");
+		if((mode == APPEND || mode == WRITE) && (PHYSFS_getWriteDir() == 0) && !hack_setupWriteDirectory())
+			throw love::Exception("Could not set write directory.");
 
 		// File already open?
 		if(file != 0)

src/modules/image/wrap_Image.cpp

 		if(luax_istype(L, 1, DATA_T))
 		{
 			Data * d = luax_checktype<Data>(L, 1, "Data", DATA_T);
-			ImageData * t;
+			ImageData * t = 0;
 			try {
 				t = instance->newImageData(d);
 			} catch (love::Exception & e) {
 			luax_convobj(L, 1, "filesystem", "newFile");
 
 		love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
-		ImageData * t = instance->newImageData(file);
+
+		ImageData * t = 0;
+		try {
+			t = instance->newImageData(file);
+		} catch (love::Exception & e) {
+			return luaL_error(L, e.what());
+		}
 		luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void*)t);
 		return 1;
 	}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.