# HG changeset patch # User sheepluva # Date 1316074298 -7200 # Node ID d31eba29e706c04460c743d17e374db6b68a2ffb # Parent 4a28d0ae9624f400d2be495d6e5e43053a4e1ac6 screenshots: display a msg on failure and log causative error diff -r 4a28d0ae9624 -r d31eba29e706 hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Thu Sep 15 09:19:56 2011 +0200 +++ b/hedgewars/hwengine.pas Thu Sep 15 10:11:38 2011 +0200 @@ -111,10 +111,18 @@ if flagMakeCapture then begin flagMakeCapture:= false; + {$IFNDEF IPHONEOS} s:= 'hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks); - WriteLnToConsole('Saving ' + s + '...'); + playSound(sndShutter); - {$IFNDEF IPHONEOS}MakeScreenshot(s);{$ENDIF} + if not MakeScreenshot(s) then + begin + WriteLnToConsole('Screenshot failed.'); + AddChatString(#5 + 'screen capture failed (lack of memory or write permissions)'); + end + else + WriteLnToConsole('Screenshot saved: ' + s); + {$ENDIF} end; end; diff -r 4a28d0ae9624 -r d31eba29e706 hedgewars/uMisc.pas --- a/hedgewars/uMisc.pas Thu Sep 15 09:19:56 2011 +0200 +++ b/hedgewars/uMisc.pas Thu Sep 15 10:11:38 2011 +0200 @@ -25,7 +25,7 @@ procedure movecursor(dx, dy: LongInt); function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; -procedure MakeScreenshot(filename: shortstring); +function MakeScreenshot(filename: shortstring): boolean; function GetTeamStatString(p: PTeam): shortstring; procedure initModule; @@ -45,9 +45,10 @@ SDL_WarpMouse(x, y); end; - -procedure MakeScreenshot(filename: shortstring); -var p: Pointer; +// captures and saves the screen. returns true on success. +function MakeScreenshot(filename: shortstring): Boolean; +var success: boolean; + p: Pointer; size: QWord; f: file; // Windows Bitmap Header @@ -79,7 +80,10 @@ // memory could not be allocated if p = nil then - exit; +begin + AddFileLog('Error: Could not allocate memory for screenshot.'); + exit(false); +end; // update header information and file name @@ -114,10 +118,18 @@ BlockWrite(f, head, sizeof(head)); BlockWrite(f, p^, size); Close(f); + success:= true; + end +else + begin + AddFileLog('Error: Could not write to ' + filename); + success:= false; end; {$IOCHECKS ON} -FreeMem(p, size) +FreeMem(p, size); + +MakeScreenshot:= success; end; // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860