summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-11-01 20:40:36 +0000
committersmatz <smatz@openttd.org>2009-11-01 20:40:36 +0000
commitd87c032e521a5f3f6caff94e519670d9d2b7ce2c (patch)
tree8d8e61564c1211a4ae44f4301cd7c92a2766cf17 /src
parentdf8c655ee66ee2efcb46327cfd2f8c66cc47a3c5 (diff)
downloadopenttd-d87c032e521a5f3f6caff94e519670d9d2b7ce2c.tar.xz
(svn r17941) -Fix: close BMP file when making screenshot fails
Diffstat (limited to 'src')
-rw-r--r--src/console_cmds.cpp2
-rw-r--r--src/screenshot.cpp13
2 files changed, 10 insertions, 5 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 1f0d3f42e..7d62d3b58 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -1219,7 +1219,7 @@ DEF_CONSOLE_CMD(ConScreenShot)
{
if (argc == 0) {
IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [big | no_con] [file name]'");
- IConsoleHelp("'big' makes a screenshot of the whole map, 'no_con' hides the console to create"
+ IConsoleHelp("'big' makes a screenshot of the whole map, 'no_con' hides the console to create "
"the screenshot. Screenshots of whole map are always drawn without console");
return true;
}
diff --git a/src/screenshot.cpp b/src/screenshot.cpp
index 283bd882f..87951c91a 100644
--- a/src/screenshot.cpp
+++ b/src/screenshot.cpp
@@ -125,9 +125,14 @@ static bool MakeBmpImage(char *name, ScreenshotCallback *callb, void *userdata,
}
/* write file header and info header and palette */
- if (fwrite(&bfh, sizeof(bfh), 1, f) != 1) return false;
- if (fwrite(&bih, sizeof(bih), 1, f) != 1) return false;
- if (pixelformat == 8) if (fwrite(rq, sizeof(rq), 1, f) != 1) return false;
+ if (fwrite(&bfh, sizeof(bfh), 1, f) != 1 || fwrite(&bih, sizeof(bih), 1, f) != 1) {
+ fclose(f);
+ return false;
+ }
+ if (pixelformat == 8 && fwrite(rq, sizeof(rq), 1, f) != 1) {
+ fclose(f);
+ return false;
+ }
/* use by default 64k temp memory */
maxlines = Clamp(65536 / padw, 16, 128);
@@ -151,7 +156,7 @@ static bool MakeBmpImage(char *name, ScreenshotCallback *callb, void *userdata,
uint32 *buff32 = (uint32 *)buff;
for (i = 0; i < padw * n; i++) buff32[i] = BSWAP32(buff32[i]);
}
-#endif
+#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
/* write each line */
while (n)