1
0
Fork 0

(svn r17941) -Fix: close BMP file when making screenshot fails

release/1.0
smatz 2009-11-01 20:40:36 +00:00
parent df8c655ee6
commit d87c032e52
2 changed files with 10 additions and 5 deletions

View File

@ -1219,7 +1219,7 @@ DEF_CONSOLE_CMD(ConScreenShot)
{ {
if (argc == 0) { if (argc == 0) {
IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [big | no_con] [file name]'"); 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"); "the screenshot. Screenshots of whole map are always drawn without console");
return true; return true;
} }

View File

@ -125,9 +125,14 @@ static bool MakeBmpImage(char *name, ScreenshotCallback *callb, void *userdata,
} }
/* write file header and info header and palette */ /* write file header and info header and palette */
if (fwrite(&bfh, sizeof(bfh), 1, f) != 1) return false; if (fwrite(&bfh, sizeof(bfh), 1, f) != 1 || fwrite(&bih, sizeof(bih), 1, f) != 1) {
if (fwrite(&bih, sizeof(bih), 1, f) != 1) return false; fclose(f);
if (pixelformat == 8) if (fwrite(rq, sizeof(rq), 1, f) != 1) return false; return false;
}
if (pixelformat == 8 && fwrite(rq, sizeof(rq), 1, f) != 1) {
fclose(f);
return false;
}
/* use by default 64k temp memory */ /* use by default 64k temp memory */
maxlines = Clamp(65536 / padw, 16, 128); maxlines = Clamp(65536 / padw, 16, 128);
@ -151,7 +156,7 @@ static bool MakeBmpImage(char *name, ScreenshotCallback *callb, void *userdata,
uint32 *buff32 = (uint32 *)buff; uint32 *buff32 = (uint32 *)buff;
for (i = 0; i < padw * n; i++) buff32[i] = BSWAP32(buff32[i]); for (i = 0; i < padw * n; i++) buff32[i] = BSWAP32(buff32[i]);
} }
#endif #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
/* write each line */ /* write each line */
while (n) while (n)