From 72efaa283f414866ded84b1121acc7d622ecfcbb Mon Sep 17 00:00:00 2001 From: rude Date: Wed, 3 Feb 2010 20:48:58 +0100 Subject: [PATCH] Fixed crash on attempt to open non-existent file. --- src/modules/filesystem/physfs/File.cpp | 10 ++++------ src/modules/image/wrap_Image.cpp | 10 ++++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/modules/filesystem/physfs/File.cpp b/src/modules/filesystem/physfs/File.cpp index 13bdf5509..1c06fa161 100644 --- a/src/modules/filesystem/physfs/File.cpp +++ b/src/modules/filesystem/physfs/File.cpp @@ -50,14 +50,12 @@ namespace physfs 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) diff --git a/src/modules/image/wrap_Image.cpp b/src/modules/image/wrap_Image.cpp index 88911309a..9793a6ded 100644 --- a/src/modules/image/wrap_Image.cpp +++ b/src/modules/image/wrap_Image.cpp @@ -49,7 +49,7 @@ namespace image if(luax_istype(L, 1, DATA_T)) { Data * d = luax_checktype(L, 1, "Data", DATA_T); - ImageData * t; + ImageData * t = 0; try { t = instance->newImageData(d); } catch (love::Exception & e) { @@ -66,7 +66,13 @@ namespace image luax_convobj(L, 1, "filesystem", "newFile"); love::filesystem::File * file = luax_checktype(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; }