DEADSOFTWARE

Fix error file not open on win32; Added stacktrace logging
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Sat, 5 Jan 2019 15:45:44 +0000 (18:45 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Sat, 5 Jan 2019 15:45:44 +0000 (18:45 +0300)
src/editor/Editor.lpr
src/editor/f_selectmap.pas
src/editor/g_resources.pas
src/engine/e_log.pas

index ccbcb60f5a95cd469fd060445b2d7c62a2f202f0..e5d615625dc332d9094a59823bba66049db33924 100644 (file)
@@ -3,8 +3,8 @@ program Editor;
 {$INCLUDE ../shared/a_modes.inc}
 
 uses
-  Forms, Interfaces,
-  GL, GLExt,
+  Forms, Interfaces, Dialogs,
+  GL, GLExt, SysUtils,
   e_graphics in '../engine/e_graphics.pas',
   e_log in '../engine/e_log.pas',
   e_textures in '../engine/e_textures.pas',
@@ -59,8 +59,23 @@ uses
   {$R *.res}
 {$ENDIF}
 
+  type
+    THandlerObject = class (TObject)
+      procedure ExceptionHandler (Sender: TObject; e: Exception);
+    end;
+
+  var
+    H: THandlerObject;
+
+  procedure THandlerObject.ExceptionHandler (Sender: TObject; e: Exception);
+  begin
+    e_WriteStackTrace(e.message);
+    MessageDlg('Unhandled exception: ' + e.message + ' (see Editor.log for more information)', mtError, [mbOK], 0);
+  end;
+
 begin
   Application.ExceptionDialog := aedOkMessageBox;
+  Application.AddOnExceptionHandler(H.ExceptionHandler, True);
   Application.Initialize();
 
   Application.CreateForm(TMainForm, MainForm);
index 8d5eecc654bee87e7eefedca55c69fc99ab46ecb..2d4882dedef40fe543cea07b5fa6808315ad0f53 100644 (file)
@@ -67,7 +67,6 @@ begin
 
   for i := 0 to list.Count - 1 do
   begin
-    writeln('GetMap "' + list.Files[i].path + '" "' + list.Files[i].name + '"');
     g_ReadResource(FileName, list.Files[i].path, list.Files[i].name, data, len);
 
     if len >= 3 then
index 6a5dbeedd227e3c8da2cc61bd07e6828342b6028..4d636eeadb9489df3ea81eebed7d85289c7c8495 100644 (file)
@@ -251,6 +251,7 @@ implementation
       begin
         len := stream.Size;
         GetMem(data, len);
+        ASSERT(data <> nil);
         //stream.ReadBuffer(data, len); (* leads to segfault *)
         for i := 0 to len - 1 do
           data[i] := stream.ReadByte();
@@ -284,6 +285,7 @@ implementation
           begin
             len := stream1.Size;
             GetMem(data, len);
+            ASSERT(data <> nil);
             //stream1.ReadBuffer(data, len); (* leads to segfault *)
             for i := 0 to len - 1 do
               data[i] := stream1.ReadByte();
index 2cabc36c176ec27ed5618a1d5d24fe0dab658273..6fdd767af6d017c93fc6909b5dba7c0d141fee79 100644 (file)
@@ -14,6 +14,7 @@ type
 procedure e_InitLog(fFileName: String; fWriteMode: TWriteMode);
 procedure e_WriteLog(TextLine: String; RecordCategory: TRecordCategory;
                      WriteTime: Boolean = True);
+procedure e_WriteStackTrace (const msg: AnsiString);
 function DecodeIPV4(ip: LongWord): string;
 
 implementation
@@ -59,6 +60,24 @@ begin
   Close(LogFile);
 end;
 
+{$I-}
+procedure e_WriteStackTrace (const msg: AnsiString);
+  var LogFile: TextFile;
+begin
+  e_WriteLog(msg, TRecordCategory.MSG_FATALERROR);
+
+  Assign(LogFile, FileName);
+  if FileExists(FileName) then
+    Append(LogFile)
+  else
+    Rewrite(LogFile);
+
+  writeln(LogFile, '=====================');
+  DumpExceptionBackTrace(LogFile);
+
+  Close(LogFile);
+end;
+
 procedure e_InitLog(fFileName: String; fWriteMode: TWriteMode);
 begin
  FileName := fFileName;