hedgewars/uDebug.pas
author alfadur
Fri, 23 Aug 2019 21:04:40 +0300
changeset 15356 3907c95227b8
parent 13503 4f00b08d6f1e
permissions -rw-r--r--
digest with byte arrays
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
     1
(*
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10306
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
     4
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
     8
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
    12
 * GNU General Public License for more details.
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
    13
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
    14
 * You should have received a copy of the GNU General Public License
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
    17
 *)
088d40d8aba2 Happy 2011 :)
koda
parents: 4900
diff changeset
    18
4403
unc0rr
parents:
diff changeset
    19
{$INCLUDE "options.inc"}
unc0rr
parents:
diff changeset
    20
unc0rr
parents:
diff changeset
    21
unit uDebug;
unc0rr
parents:
diff changeset
    22
unc0rr
parents:
diff changeset
    23
interface
unc0rr
parents:
diff changeset
    24
unc0rr
parents:
diff changeset
    25
procedure OutError(Msg: shortstring; isFatalError: boolean);
11537
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11512
diff changeset
    26
//procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); inline;
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11512
diff changeset
    27
function checkFails(Assert: boolean; Msg: shortstring; isFatal: boolean): boolean;
11512
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11342
diff changeset
    28
function SDLCheck(Assert: boolean; Msg: shortstring; isFatal: boolean): boolean;
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11342
diff changeset
    29
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11342
diff changeset
    30
var
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11342
diff changeset
    31
    allOK: boolean;
4403
unc0rr
parents:
diff changeset
    32
unc0rr
parents:
diff changeset
    33
implementation
10306
4fca8bcfaff0 clean up halting a little
sheepluva
parents: 10108
diff changeset
    34
uses SDLh, uConsole, uCommands, uConsts;
4403
unc0rr
parents:
diff changeset
    35
unc0rr
parents:
diff changeset
    36
procedure OutError(Msg: shortstring; isFatalError: boolean);
unc0rr
parents:
diff changeset
    37
begin
unc0rr
parents:
diff changeset
    38
WriteLnToConsole(Msg);
unc0rr
parents:
diff changeset
    39
if isFatalError then
10306
4fca8bcfaff0 clean up halting a little
sheepluva
parents: 10108
diff changeset
    40
    begin
8437
93b647d6a00f uConsole on a diet
koda
parents: 7134
diff changeset
    41
    ParseCommand('fatal ' + lastConsoleline, true);
10306
4fca8bcfaff0 clean up halting a little
sheepluva
parents: 10108
diff changeset
    42
    // hint for the 'coverity' source analyzer
4fca8bcfaff0 clean up halting a little
sheepluva
parents: 10108
diff changeset
    43
    // this halt is never actually reached because ParseCommands will halt first
4fca8bcfaff0 clean up halting a little
sheepluva
parents: 10108
diff changeset
    44
    halt(HaltFatalError);
4fca8bcfaff0 clean up halting a little
sheepluva
parents: 10108
diff changeset
    45
    end;
4403
unc0rr
parents:
diff changeset
    46
end;
unc0rr
parents:
diff changeset
    47
unc0rr
parents:
diff changeset
    48
procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean);
unc0rr
parents:
diff changeset
    49
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 4976
diff changeset
    50
if not Assert then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 4976
diff changeset
    51
    OutError(Msg, isFatal)
4403
unc0rr
parents:
diff changeset
    52
end;
unc0rr
parents:
diff changeset
    53
11537
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11512
diff changeset
    54
function checkFails(Assert: boolean; Msg: shortstring; isFatal: boolean): boolean;
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11512
diff changeset
    55
begin
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11512
diff changeset
    56
    if not Assert then
13083
dd904dd9c587 Fix frontend error dialog always displaying "failed" as last engine message after engine crash
Wuzzy <Wuzzy2@mail.ru>
parents: 11537
diff changeset
    57
        begin
dd904dd9c587 Fix frontend error dialog always displaying "failed" as last engine message after engine crash
Wuzzy <Wuzzy2@mail.ru>
parents: 11537
diff changeset
    58
        lastConsoleLine:= Msg;
13503
4f00b08d6f1e Propagate fatal errors to OutError if checkFails called
Wuzzy <Wuzzy2@mail.ru>
parents: 13489
diff changeset
    59
        OutError(Msg, isFatal);
13083
dd904dd9c587 Fix frontend error dialog always displaying "failed" as last engine message after engine crash
Wuzzy <Wuzzy2@mail.ru>
parents: 11537
diff changeset
    60
        end;
11537
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11512
diff changeset
    61
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11512
diff changeset
    62
    allOK:= allOK and (Assert or (not isFatal));
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11512
diff changeset
    63
    checkFails:= (not Assert) and isFatal
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11512
diff changeset
    64
end;
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11512
diff changeset
    65
11512
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11342
diff changeset
    66
function SDLCheck(Assert: boolean; Msg: shortstring; isFatal: boolean): boolean;
7134
beb16926ae5c Some improvements to pas2c
unc0rr
parents: 6700
diff changeset
    67
var s: shortstring;
4403
unc0rr
parents:
diff changeset
    68
begin
11512
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11342
diff changeset
    69
    if not Assert then
7134
beb16926ae5c Some improvements to pas2c
unc0rr
parents: 6700
diff changeset
    70
    begin
11512
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11342
diff changeset
    71
        s:= SDL_GetError();
13489
480ea997036b Send proper failure error message when image loading has failed
Wuzzy <Wuzzy2@mail.ru>
parents: 13083
diff changeset
    72
        OutError(Msg + ': ' + s, isFatal)
11512
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11342
diff changeset
    73
    end;
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11342
diff changeset
    74
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11342
diff changeset
    75
    allOK:= allOK and (Assert or (not isFatal));
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11342
diff changeset
    76
    SDLCheck:= (not Assert) and isFatal
4403
unc0rr
parents:
diff changeset
    77
end;
unc0rr
parents:
diff changeset
    78
4900
8ad0e23e6d63 addfilelog <3 debugfile
koda
parents: 4403
diff changeset
    79
end.