From: DeaDDooMER Date: Sat, 5 Jan 2019 15:45:44 +0000 (+0300) Subject: Fix error file not open on win32; Added stacktrace logging X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=67cddfbb3e682ca99f9b9a2e98e87332bd5c30be;p=d2df-editor.git Fix error file not open on win32; Added stacktrace logging --- diff --git a/src/editor/Editor.lpr b/src/editor/Editor.lpr index ccbcb60..e5d6156 100644 --- a/src/editor/Editor.lpr +++ b/src/editor/Editor.lpr @@ -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); diff --git a/src/editor/f_selectmap.pas b/src/editor/f_selectmap.pas index 8d5eecc..2d4882d 100644 --- a/src/editor/f_selectmap.pas +++ b/src/editor/f_selectmap.pas @@ -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 diff --git a/src/editor/g_resources.pas b/src/editor/g_resources.pas index 6a5dbee..4d636ee 100644 --- a/src/editor/g_resources.pas +++ b/src/editor/g_resources.pas @@ -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(); diff --git a/src/engine/e_log.pas b/src/engine/e_log.pas index 2cabc36..6fdd767 100644 --- a/src/engine/e_log.pas +++ b/src/engine/e_log.pas @@ -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;