From: Côme Chilliet Date: Wed, 14 Dec 2016 14:35:43 +0000 (+0700) Subject: Improved error reporting of screenshot saving, fixed screenshot path. X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=24c49b5bd8c82cd433fffe3456334bd3be743da9;p=lugaru.git Improved error reporting of screenshot saving, fixed screenshot path. --- diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 921058b..1ed3b8a 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -348,13 +348,9 @@ void Screenshot (void) char filename[1024]; time_t t = time(NULL); struct tm *tme = localtime(&t); - sprintf(filename, "Screenshots/Screenshot-%04d%02d%02d-%02d%02d%02d.png", + sprintf(filename, "Screenshot-%04d%02d%02d-%02d%02d%02d.png", tme->tm_year + 1900, tme->tm_mon + 1, tme->tm_mday, tme->tm_hour, tme->tm_min, tme->tm_sec); -#if defined(_WIN32) - mkdir("Screenshots"); -#endif - save_screenshot(filename); } diff --git a/Source/Utils/ImageIO.cpp b/Source/Utils/ImageIO.cpp index 8bd5bfc..508c10f 100644 --- a/Source/Utils/ImageIO.cpp +++ b/Source/Utils/ImageIO.cpp @@ -104,10 +104,13 @@ static bool load_jpg(const char *file_name, ImageRec &tex) struct my_error_mgr jerr; JSAMPROW buffer[1]; /* Output row buffer */ int row_stride; /* physical row width in output buffer */ + errno = 0; FILE *infile = fopen(file_name, "rb"); - if (infile == NULL) + if (infile == NULL) { + perror((std::string("Couldn't open file ") + file_name).c_str()); return false; + } cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; @@ -154,10 +157,11 @@ static bool load_png(const char *file_name, ImageRec &tex) int bit_depth, color_type, interlace_type; bool retval = false; png_byte **row_pointers = NULL; + errno = 0; FILE *fp = fopen(file_name, "rb"); if (fp == NULL) { - cerr << file_name << " not found" << endl; + perror((std::string("Couldn't open file ") + file_name).c_str()); return false; } @@ -237,9 +241,12 @@ static bool save_screenshot_png(const char *file_name) png_infop info_ptr = NULL; bool retval = false; + errno = 0; fp = fopen(file_name, "wb"); - if (fp == NULL) + if (fp == NULL) { + perror((std::string("Couldn't open file ") + file_name).c_str()); return false; + } png_bytep *row_pointers = new png_bytep[kContextHeight]; png_bytep screenshot = new png_byte[kContextWidth * kContextHeight * 3];