DEADSOFTWARE

show heap dump only when leaks are detected
[d2df-editor.git] / src / editor / Editor.lpr
index 91df01a9a42c55124e95fdcc9e4fd2350619781a..3889b5109fd514598830302435c888ccfe509be8 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',
@@ -15,6 +15,12 @@ uses
   WADEDITOR in '../shared/WADEDITOR.pas',
   WADSTRUCT in '../shared/WADSTRUCT.pas',
   CONFIG in '../shared/CONFIG.pas',
+  xstreams in '../shared/xstreams.pas',
+  dfzip in '../shared/dfzip.pas',
+  sfs in '../sfs/sfs.pas',
+  sfsPlainFS in '../sfs/sfsPlainFS.pas',
+  sfsZipFS in '../sfs/sfsZipFS.pas',
+
   f_about in 'f_about.pas' {AboutForm},
   f_options in 'f_options.pas' {OptionsForm},
   f_main in 'f_main.pas' {MainForm},
@@ -49,12 +55,36 @@ uses
   g_language in 'g_language.pas',
   f_selectlang in 'f_selectlang.pas' {SelectLanguageForm};
 
-{$R *.res}
+{$IFDEF WINDOWS}
+  {$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();
 
+{$IF DECLARED(UseHeapTrace)}
+  (* http://wiki.freepascal.org/heaptrc *)
+  GlobalSkipIfNoLeaks := True;
+  //SetHeapTraceOutput('EditorLeaks.log');
+  //HaltOnError := False;
+{$ENDIF}
+
   Application.CreateForm(TMainForm, MainForm);
   Application.CreateForm(TOptionsForm, OptionsForm);
   Application.CreateForm(TAboutForm, AboutForm);