hedgewars/hwengine.pas
changeset 13843 cf7626f46bb2
parent 13586 41e0446fb254
child 14220 3c36a4e66c82
equal deleted inserted replaced
13842:db1b680bd8d3 13843:cf7626f46bb2
    43 function RunEngine(argc: LongInt; argv: PPChar): LongInt; cdecl; export;
    43 function RunEngine(argc: LongInt; argv: PPChar): LongInt; cdecl; export;
    44 
    44 
    45 procedure preInitEverything();
    45 procedure preInitEverything();
    46 procedure initEverything(complete:boolean);
    46 procedure initEverything(complete:boolean);
    47 procedure freeEverything(complete:boolean);
    47 procedure freeEverything(complete:boolean);
       
    48 {$IFNDEF PAS2C}
    48 procedure catchUnhandledException(Obj: TObject; Addr: Pointer; FrameCount: Longint; Frames: PPointer);
    49 procedure catchUnhandledException(Obj: TObject; Addr: Pointer; FrameCount: Longint; Frames: PPointer);
       
    50 {$ENDIF}
    49 
    51 
    50 implementation
    52 implementation
    51 {$ELSE}
    53 {$ELSE}
    52 procedure preInitEverything(); forward;
    54 procedure preInitEverything(); forward;
    53 procedure initEverything(complete:boolean); forward;
    55 procedure initEverything(complete:boolean); forward;
    54 procedure freeEverything(complete:boolean); forward;
    56 procedure freeEverything(complete:boolean); forward;
       
    57 {$IFNDEF PAS2C}
    55 procedure catchUnhandledException(Obj: TObject; Addr: Pointer; FrameCount: Longint; Frames: PPointer); forward;
    58 procedure catchUnhandledException(Obj: TObject; Addr: Pointer; FrameCount: Longint; Frames: PPointer); forward;
       
    59 {$ENDIF}
    56 {$ENDIF}
    60 {$ENDIF}
    57 
    61 
    58 {$IFDEF WIN32}
    62 {$IFDEF WIN32}
    59 type TSetProcessDpiAwareness = function(value: Integer): Integer; stdcall;
    63 type TSetProcessDpiAwareness = function(value: Integer): Integer; stdcall;
    60 var SetProcessDpiAwareness: TSetProcessDpiAwareness;
    64 var SetProcessDpiAwareness: TSetProcessDpiAwareness;
   598     end;
   602     end;
   599 
   603 
   600     freeEverything(false);
   604     freeEverything(false);
   601 end;
   605 end;
   602 
   606 
       
   607 {$IFNDEF PAS2C}
   603 // Write backtrace to console and log when an unhandled exception occurred
   608 // Write backtrace to console and log when an unhandled exception occurred
   604 procedure catchUnhandledException(Obj: TObject; Addr: Pointer; FrameCount: Longint; Frames: PPointer);
   609 procedure catchUnhandledException(Obj: TObject; Addr: Pointer; FrameCount: Longint; Frames: PPointer);
   605 var
   610 var
   606   Message: string;
   611   Message: string;
   607   i: LongInt;
   612   i: LongInt;
   619     begin
   624     begin
   620       for i := 0 to FrameCount - 1 do
   625       for i := 0 to FrameCount - 1 do
   621         WriteLnToConsole(BackTraceStrFunc(Frames[i]));
   626         WriteLnToConsole(BackTraceStrFunc(Frames[i]));
   622     end;
   627     end;
   623 end;
   628 end;
       
   629 {$ENDIF}
   624 
   630 
   625 {$IFDEF HWLIBRARY}
   631 {$IFDEF HWLIBRARY}
   626 function RunEngine(argc: LongInt; argv: PPChar): LongInt; cdecl; export;
   632 function RunEngine(argc: LongInt; argv: PPChar): LongInt; cdecl; export;
   627 begin
   633 begin
   628     operatingsystem_parameter_argc:= argc;
   634     operatingsystem_parameter_argc:= argc;
   647 ///////////////////////////////////////////////////////////////////////////////
   653 ///////////////////////////////////////////////////////////////////////////////
   648 {$IFDEF PAS2C}
   654 {$IFDEF PAS2C}
   649     // workaround for pascal's ParamStr and ParamCount
   655     // workaround for pascal's ParamStr and ParamCount
   650     init(argc, argv);
   656     init(argc, argv);
   651 {$ENDIF}
   657 {$ENDIF}
       
   658 {$IFNDEF PAS2C}
   652     // Custom procedure for unhandled exceptions; ExceptProc is used by sysutils module
   659     // Custom procedure for unhandled exceptions; ExceptProc is used by sysutils module
   653     ExceptProc:= @catchUnhandledException;
   660     ExceptProc:= @catchUnhandledException;
       
   661 {$ENDIF}
   654 
   662 
   655     preInitEverything();
   663     preInitEverything();
   656 
   664 
   657     GetParams();
   665     GetParams();
   658 
   666