equal
deleted
inserted
replaced
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 procedure catchUnhandledException(Obj: TObject; Addr: Pointer; FrameCount: Longint; Frames: PPointer); |
48 |
49 |
49 implementation |
50 implementation |
50 {$ELSE} |
51 {$ELSE} |
51 procedure preInitEverything(); forward; |
52 procedure preInitEverything(); forward; |
52 procedure initEverything(complete:boolean); forward; |
53 procedure initEverything(complete:boolean); forward; |
53 procedure freeEverything(complete:boolean); forward; |
54 procedure freeEverything(complete:boolean); forward; |
|
55 procedure catchUnhandledException(Obj: TObject; Addr: Pointer; FrameCount: Longint; Frames: PPointer); forward; |
54 {$ENDIF} |
56 {$ENDIF} |
55 |
57 |
56 {$IFDEF WIN32} |
58 {$IFDEF WIN32} |
57 type TSetProcessDpiAwareness = function(value: Integer): Integer; stdcall; |
59 type TSetProcessDpiAwareness = function(value: Integer): Integer; stdcall; |
58 var SetProcessDpiAwareness: TSetProcessDpiAwareness; |
60 var SetProcessDpiAwareness: TSetProcessDpiAwareness; |
595 end; |
597 end; |
596 |
598 |
597 freeEverything(false); |
599 freeEverything(false); |
598 end; |
600 end; |
599 |
601 |
|
602 // Write backtrace to console and log when an unhandled exception occurred |
|
603 procedure catchUnhandledException(Obj: TObject; Addr: Pointer; FrameCount: Longint; Frames: PPointer); |
|
604 var |
|
605 Message: string; |
|
606 i: LongInt; |
|
607 begin |
|
608 WriteLnToConsole('An unhandled exception occurred at $' + HexStr(Addr) + ':'); |
|
609 if Obj is exception then |
|
610 begin |
|
611 Message := Exception(Obj).ClassName + ': ' + Exception(Obj).Message; |
|
612 WriteLnToConsole(Message); |
|
613 end |
|
614 else |
|
615 WriteLnToConsole('Exception object ' + Obj.ClassName + ' is not of class Exception.'); |
|
616 WriteLnToConsole(BackTraceStrFunc(Addr)); |
|
617 if (FrameCount > 0) then |
|
618 begin |
|
619 for i := 0 to FrameCount - 1 do |
|
620 WriteLnToConsole(BackTraceStrFunc(Frames[i])); |
|
621 end; |
|
622 end; |
|
623 |
600 {$IFDEF HWLIBRARY} |
624 {$IFDEF HWLIBRARY} |
601 function RunEngine(argc: LongInt; argv: PPChar): LongInt; cdecl; export; |
625 function RunEngine(argc: LongInt; argv: PPChar): LongInt; cdecl; export; |
602 begin |
626 begin |
603 operatingsystem_parameter_argc:= argc; |
627 operatingsystem_parameter_argc:= argc; |
604 operatingsystem_parameter_argv:= argv; |
628 operatingsystem_parameter_argv:= argv; |
622 /////////////////////////////////////////////////////////////////////////////// |
646 /////////////////////////////////////////////////////////////////////////////// |
623 {$IFDEF PAS2C} |
647 {$IFDEF PAS2C} |
624 // workaround for pascal's ParamStr and ParamCount |
648 // workaround for pascal's ParamStr and ParamCount |
625 init(argc, argv); |
649 init(argc, argv); |
626 {$ENDIF} |
650 {$ENDIF} |
|
651 // Custom procedure for unhandled exceptions; ExceptProc is used by sysutils module |
|
652 ExceptProc:= @catchUnhandledException; |
|
653 |
627 preInitEverything(); |
654 preInitEverything(); |
628 |
655 |
629 GetParams(); |
656 GetParams(); |
630 |
657 |
631 if GameType = gmtLandPreview then |
658 if GameType = gmtLandPreview then |
632 GenLandPreview() |
659 GenLandPreview() |
633 else if GameType <> gmtSyntax then |
660 else if (GameType <> gmtBadSyntax) and (GameType <> gmtSyntaxHelp) then |
634 Game(); |
661 Game(); |
635 |
662 |
636 // return 1 when engine is not called correctly |
663 // return error when engine is not called correctly |
637 if GameType = gmtSyntax then |
664 if GameType = gmtBadSyntax then |
638 {$IFDEF PAS2C} |
665 {$IFDEF PAS2C} |
639 exit(HaltUsageError); |
666 exit(HaltUsageError); |
640 {$ELSE} |
667 {$ELSE} |
641 halt(HaltUsageError); |
668 halt(HaltUsageError); |
642 {$ENDIF} |
669 {$ENDIF} |