DEADSOFTWARE

fixed segfault on loading invalid maps
[d2df-sdl.git] / src / engine / e_log.pas
index 3a8d0adc2900ef25e1f3fb3ea896c54320504e3e..ed4cfe525f4479957cca8754c690a99be9f64b4c 100644 (file)
@@ -41,6 +41,10 @@ function DecodeIPV4 (ip: LongWord): string;
 procedure e_InitWritelnDriver ();
 
 procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TRecordCategory=MSG_NOTIFY; writeTime: Boolean=true);
+procedure e_LogWriteln (const s: AnsiString; category: TRecordCategory=MSG_NOTIFY; writeTime: Boolean=true);
+
+
+procedure e_WriteStackTrace (const msg: AnsiString);
 
 
 var
@@ -70,6 +74,12 @@ begin
 end;
 
 
+procedure e_LogWriteln (const s: AnsiString; category: TRecordCategory=MSG_NOTIFY; writeTime: Boolean=true);
+begin
+  e_LogWritefln('%s', [s], category, writeTime);
+end;
+
+
 // returns formatted string if `writerCB` is `nil`, empty string otherwise
 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
@@ -233,6 +243,24 @@ begin
 end;
 
 
+{$I-}
+procedure e_WriteStackTrace (const msg: AnsiString);
+var
+  tfo: TextFile;
+begin
+  e_LogWriteln(msg, MSG_FATALERROR);
+  if (Length(FileName) > 0) then
+  begin
+    if xlogFileOpened then CloseFile(xlogFile);
+    xlogFileOpened := false;
+    AssignFile(tfo, FileName);
+    Append(tfo);
+    if (IOResult <> 0) then Rewrite(tfo);
+    if (IOResult = 0) then begin writeln(tfo, '====================='); DumpExceptionBackTrace(tfo); CloseFile(tfo); end;
+  end;
+end;
+
+
 procedure e_DeinitLog ();
 begin
   if xlogFileOpened then CloseFile(xlogFile);