1
0
Fork 0

(svn r18155) -Codechange: in MakeScreenshotName(), don't return pointer to local static variable - use global one instead

release/1.0
smatz 2009-11-17 23:08:55 +00:00
parent d747a643cc
commit 4eaa558ca1
3 changed files with 12 additions and 10 deletions

View File

@ -1232,7 +1232,7 @@ DEF_CONSOLE_CMD(ConScreenShot)
/* screenshot filename */ /* screenshot filename */
name = argv[1]; name = argv[1];
} else { } else {
/* screenshot argv[1] argv[2] - invalid*/ /* screenshot argv[1] argv[2] - invalid */
return false; return false;
} }
} }

View File

@ -27,6 +27,7 @@ char _screenshot_format_name[8];
uint _num_screenshot_formats; uint _num_screenshot_formats;
uint _cur_screenshot_format; uint _cur_screenshot_format;
char _screenshot_name[128]; char _screenshot_name[128];
char _full_screenshot_name[MAX_PATH];
static ScreenshotType _screenshot_type; static ScreenshotType _screenshot_type;
/* called by the ScreenShot proc to generate screenshot lines. */ /* called by the ScreenShot proc to generate screenshot lines. */
@ -585,20 +586,19 @@ static const char *MakeScreenshotName(const char *ext)
size_t len = strlen(_screenshot_name); size_t len = strlen(_screenshot_name);
snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext); snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext);
static char filename[MAX_PATH];
for (uint serial = 1;; serial++) { for (uint serial = 1;; serial++) {
if (snprintf(filename, lengthof(filename), "%s%s", _personal_dir, _screenshot_name) >= (int)lengthof(filename)) { if (snprintf(_full_screenshot_name, lengthof(_full_screenshot_name), "%s%s", _personal_dir, _screenshot_name) >= (int)lengthof(_full_screenshot_name)) {
/* We need more characters than MAX_PATH -> end with error */ /* We need more characters than MAX_PATH -> end with error */
filename[0] = '\0'; _full_screenshot_name[0] = '\0';
break; break;
} }
if (!generate) break; // allow overwriting of non-automatic filenames if (!generate) break; // allow overwriting of non-automatic filenames
if (!FileExists(filename)) break; if (!FileExists(_full_screenshot_name)) break;
/* If file exists try another one with same name, but just with a higher index */ /* If file exists try another one with same name, but just with a higher index */
snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, "#%u.%s", serial, ext); snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, "#%u.%s", serial, ext);
} }
return filename; return _full_screenshot_name;
} }
void RequestScreenshot(ScreenshotType t, const char *name) void RequestScreenshot(ScreenshotType t, const char *name)

View File

@ -17,10 +17,11 @@ void InitializeScreenshotFormats();
const char *GetScreenshotFormatDesc(int i); const char *GetScreenshotFormatDesc(int i);
void SetScreenshotFormat(int i); void SetScreenshotFormat(int i);
/** Type of requested screenshot */
enum ScreenshotType { enum ScreenshotType {
SC_NONE, SC_NONE, ///< No screenshot requested
SC_VIEWPORT, SC_VIEWPORT, ///< Screenshot of viewport
SC_WORLD SC_WORLD, ///< World screenshot
}; };
bool MakeScreenshot(); bool MakeScreenshot();
@ -30,6 +31,7 @@ bool IsScreenshotRequested();
extern char _screenshot_format_name[8]; extern char _screenshot_format_name[8];
extern uint _num_screenshot_formats; extern uint _num_screenshot_formats;
extern uint _cur_screenshot_format; extern uint _cur_screenshot_format;
extern char _screenshot_name[]; extern char _screenshot_name[128];
extern char _full_screenshot_name[MAX_PATH];
#endif /* SCREENSHOT_H */ #endif /* SCREENSHOT_H */