clean up halting a little
authorsheepluva
Sun, 15 Jun 2014 00:02:25 +0200
changeset 10306 4fca8bcfaff0
parent 10305 17f3ca06e39a
child 10307 e13d3147f15b
clean up halting a little
hedgewars/hwengine.pas
hedgewars/uConsts.pas
hedgewars/uDebug.pas
hedgewars/uIO.pas
hedgewars/uMatrix.pas
hedgewars/uRender.pas
hedgewars/uScript.pas
hedgewars/uVideoRec.pas
--- a/hedgewars/hwengine.pas	Sat Jun 14 23:59:20 2014 +0200
+++ b/hedgewars/hwengine.pas	Sun Jun 15 00:02:25 2014 +0200
@@ -575,9 +575,9 @@
     // return 1 when engine is not called correctly
     if GameType = gmtSyntax then
         {$IFDEF PAS2C}
-        exit(1);
+        exit(HaltUsageError);
         {$ELSE}
-        halt(1);
+        halt(HaltUsageError);
         {$ENDIF}
 
 {$IFDEF HWLIBRARY}
--- a/hedgewars/uConsts.pas	Sat Jun 14 23:59:20 2014 +0200
+++ b/hedgewars/uConsts.pas	Sun Jun 15 00:02:25 2014 +0200
@@ -26,6 +26,17 @@
 {$INCLUDE "config.inc"}
 
 const
+    HaltNoError      = 0;
+    HaltUsageError   = 1;
+    HaltFatalError   = 2;
+    HaltStartupError = 3;
+
+    // for automatic tests
+    HaltTestSuccess  =   0;
+    HaltTestFailed   =  10;
+    HaltTestLuaError =  11;
+
+
     sfMax = 1000;
 
     // message constants
@@ -302,10 +313,6 @@
 
     kSystemSoundID_Vibrate = $00000FFF;
 
-    rtnTestSuccess = $00000000;
-    rtnTestFailed  = $00000001;
-    rtnTestLuaErr  = $00000002;
-
 implementation
 
 end.
--- a/hedgewars/uDebug.pas	Sat Jun 14 23:59:20 2014 +0200
+++ b/hedgewars/uDebug.pas	Sun Jun 15 00:02:25 2014 +0200
@@ -27,13 +27,18 @@
 procedure SDLTry(Assert: boolean; isFatal: boolean);
 
 implementation
-uses SDLh, uConsole, uCommands;
+uses SDLh, uConsole, uCommands, uConsts;
 
 procedure OutError(Msg: shortstring; isFatalError: boolean);
 begin
 WriteLnToConsole(Msg);
 if isFatalError then
+    begin
     ParseCommand('fatal ' + lastConsoleline, true);
+    // hint for the 'coverity' source analyzer
+    // this halt is never actually reached because ParseCommands will halt first
+    halt(HaltFatalError);
+    end;
 end;
 
 procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean);
--- a/hedgewars/uIO.pas	Sat Jun 14 23:59:20 2014 +0200
+++ b/hedgewars/uIO.pas	Sun Jun 15 00:02:25 2014 +0200
@@ -416,7 +416,7 @@
     SendIPC('E' + s);
     // TODO: should we try to clean more stuff here?
     SDL_Quit;
-    halt(2)
+    halt(HaltFatalError);
 end;
 
 procedure doPut(putX, putY: LongInt; fromAI: boolean);
--- a/hedgewars/uMatrix.pas	Sat Jun 14 23:59:20 2014 +0200
+++ b/hedgewars/uMatrix.pas	Sun Jun 15 00:02:25 2014 +0200
@@ -44,6 +44,8 @@
 
 implementation
 
+uses uDebug;
+
 const
     MATRIX_STACK_SIZE = 10;
 
@@ -258,7 +260,7 @@
             write(Result[i, j]);
           writeln;
         end;
-        halt(0);
+        TryDo(false, 'error in matrix multiplication?!', true);
     end;
     {$ENDIF}
 
--- a/hedgewars/uRender.pas	Sat Jun 14 23:59:20 2014 +0200
+++ b/hedgewars/uRender.pas	Sun Jun 15 00:02:25 2014 +0200
@@ -159,7 +159,7 @@
     if IOResult <> 0 then
     begin
         AddFileLog('Unable to load ' + shaderFile);
-        halt(-1);
+        halt(HaltStartupError);
     end;
 
     source:='';
@@ -195,7 +195,7 @@
     if compileResult <> GL_TRUE then
     begin
         WriteLnToConsole('Shader compilation failed, halting');
-        halt(-1);
+        halt(HaltStartupError);
     end;
 
     CompileShader:= shader;
@@ -239,7 +239,7 @@
     if linkResult <> GL_TRUE then
     begin
         WriteLnToConsole('Linking program failed, halting');
-        halt(-1);
+        halt(HaltStartupError);
     end;
 
     CompileProgram:= program_;
@@ -333,7 +333,7 @@
     if err <> GLEW_OK then
     begin
         WriteLnToConsole('Failed to initialize GLEW.');
-        halt;
+        halt(HaltStartupError);
     end;
 {$ENDIF}
 
--- a/hedgewars/uScript.pas	Sat Jun 14 23:59:20 2014 +0200
+++ b/hedgewars/uScript.pas	Sun Jun 15 00:02:25 2014 +0200
@@ -136,7 +136,7 @@
     WriteLnToConsole(s);
     AddChatString(#5 + s);
     if cTestLua then
-        halt(rtnTestLuaErr);
+        halt(HaltTestLuaError);
 end;
 
 procedure LuaCallError(error, call, paramsyntax: shortstring);
@@ -2849,8 +2849,8 @@
 
 if cTestLua then
     begin
-    ScriptSetInteger('TEST_SUCCESSFUL'  ,rtnTestSuccess);
-    ScriptSetInteger('TEST_FAILED'      ,rtnTestFailed);
+    ScriptSetInteger('TEST_SUCCESSFUL'   , HaltTestSuccess);
+    ScriptSetInteger('TEST_FAILED'       , HaltTestFailed);
     lua_register(luaState, _P'EndLuaTest', @lc_endluatest);
     end;
 
--- a/hedgewars/uVideoRec.pas	Sat Jun 14 23:59:20 2014 +0200
+++ b/hedgewars/uVideoRec.pas	Sun Jun 15 00:02:25 2014 +0200
@@ -117,7 +117,7 @@
         , PChar(ansistring(cVideoCodec))
         , PChar(ansistring(cAudioCodec))
         , cScreenWidth, cScreenHeight, cVideoFramerateNum, cVideoFramerateDen, cVideoQuality) < 0 then
-        halt(-1);
+        halt(HaltFatalError);
 
     numPixels:= cScreenWidth*cScreenHeight;
     YCbCr_Planes[0]:= GetMem(numPixels);