From 081024eb8fedf1b3bfbcf8e800804e66bbddb5fd Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 6 Feb 2021 17:53:53 +0000 Subject: [PATCH] Fix build for screenshot=legacy opengl=0 Reported-by: dimag0g --- common/include/pcx.h | 2 +- similar/2d/pcx.cpp | 16 ++++++++++------ similar/main/game.cpp | 13 ++++++------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/common/include/pcx.h b/common/include/pcx.h index 6ba3fa4b3..aba668c1c 100644 --- a/common/include/pcx.h +++ b/common/include/pcx.h @@ -57,7 +57,7 @@ pcx_result pcx_read_bitmap_or_default(const char * filename, grs_main_bitmap &bm // Writes the bitmap bmp to filename, using palette. Returns error code. #if !DXX_USE_OGL && DXX_USE_SCREENSHOT_FORMAT_LEGACY -pcx_result pcx_write_bitmap(PHYSFS_File *, const grs_bitmap *bmp, palette_array_t &palette); +unsigned pcx_write_bitmap(PHYSFS_File *, const grs_bitmap *bmp, palette_array_t &palette); #endif const char *pcx_errormsg(pcx_result error_number); diff --git a/similar/2d/pcx.cpp b/similar/2d/pcx.cpp index ecdf76bb7..ef641b4c0 100644 --- a/similar/2d/pcx.cpp +++ b/similar/2d/pcx.cpp @@ -265,7 +265,7 @@ pcx_result pcx_read_bitmap_or_default(const char *const filename, grs_main_bitma } #if !DXX_USE_OGL && DXX_USE_SCREENSHOT_FORMAT_LEGACY -pcx_result pcx_write_bitmap(PHYSFS_File *const PCXfile, const grs_bitmap *const bmp, palette_array_t &palette) +unsigned pcx_write_bitmap(PHYSFS_File *const PCXfile, const grs_bitmap *const bmp, palette_array_t &palette) { int retval; ubyte data; @@ -282,7 +282,7 @@ pcx_result pcx_write_bitmap(PHYSFS_File *const PCXfile, const grs_bitmap *const if (PHYSFS_write(PCXfile, &header, PCXHEADER_SIZE, 1) != 1) { - return pcx_result::ERROR_WRITING; + return 1; } { @@ -294,7 +294,7 @@ pcx_result pcx_write_bitmap(PHYSFS_File *const PCXfile, const grs_bitmap *const { if (!pcx_encode_line(i, bm_w, PCXfile)) { - return pcx_result::ERROR_WRITING; + return 1; } } } @@ -303,16 +303,18 @@ pcx_result pcx_write_bitmap(PHYSFS_File *const PCXfile, const grs_bitmap *const data = 12; if (PHYSFS_write(PCXfile, &data, 1, 1) != 1) { - return pcx_result::ERROR_WRITING; + return 1; } retval = PHYSFS_write(PCXfile, &palette[0], sizeof(palette), 1); if (retval !=1) { - return pcx_result::ERROR_WRITING; + return 1; } - return pcx_result::SUCCESS; + return 0; } +namespace { + // returns number of bytes written into outBuff, 0 if failed int pcx_encode_line(const uint8_t *inBuff, uint_fast32_t inLen, PHYSFS_File *fp) { @@ -380,6 +382,8 @@ int pcx_encode_byte(ubyte byt, ubyte cnt, PHYSFS_File *fid) } return 0; } + +} #endif //text for error messges diff --git a/similar/main/game.cpp b/similar/main/game.cpp index 2f9c0a34a..f06da0473 100644 --- a/similar/main/game.cpp +++ b/similar/main/game.cpp @@ -865,7 +865,6 @@ void save_screen_shot(int automap_flag) #undef DXX_SCREENSHOT_TIME_FORMAT_STRING #undef DXX_SCREENSHOT_FILE_EXTENSION } - unsigned write_error; if (const auto file = PHYSFSX_openWriteBuffered(savename)) { if (!automap_flag) @@ -876,11 +875,11 @@ void save_screen_shot(int automap_flag) glReadBuffer(GL_FRONT); #endif #if DXX_USE_SCREENSHOT_FORMAT_PNG - write_error = write_screenshot_png(file, tm, grd_curscreen->sc_canvas.cv_bitmap, void /* unused */); + auto write_error = write_screenshot_png(file, tm, grd_curscreen->sc_canvas.cv_bitmap, void /* unused */); #elif DXX_USE_SCREENSHOT_FORMAT_LEGACY write_bmp(file, grd_curscreen->get_screen_width(), grd_curscreen->get_screen_height()); /* write_bmp never fails */ - write_error = 0; + std::false_type write_error; #endif #else grs_canvas &screen_canv = grd_curscreen->sc_canvas; @@ -898,11 +897,13 @@ void save_screen_shot(int automap_flag) i.b <<= 2; } #if DXX_USE_SCREENSHOT_FORMAT_PNG - write_error = write_screenshot_png(file, tm, grd_curscreen->sc_canvas.cv_bitmap, pal); + auto write_error = write_screenshot_png(file, tm, grd_curscreen->sc_canvas.cv_bitmap, pal); #elif DXX_USE_SCREENSHOT_FORMAT_LEGACY - write_error = pcx_write_bitmap(file, &temp_canv->cv_bitmap, pal); + auto write_error = pcx_write_bitmap(file, &temp_canv->cv_bitmap, pal); #endif #endif + if (write_error) + PHYSFS_delete(savename); } else { @@ -912,8 +913,6 @@ void save_screen_shot(int automap_flag) con_printf(CON_URGENT, "Failed to open screenshot file for writing: %s", savename); return; } - if (write_error) - PHYSFS_delete(savename); } #endif