Lua: Fix HideHog causing engine crash when provided with invalid gear ID or hog was hidden
authorWuzzy <almikes@aol.com>
Thu, 27 Apr 2017 19:09:01 +0200
changeset 12360 a775a61e02ab
parent 12359 81ab841a0da5
child 12361 05fe955e2763
Lua: Fix HideHog causing engine crash when provided with invalid gear ID or hog was hidden
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Thu Apr 27 16:29:23 2017 +0200
+++ b/ChangeLog.txt	Thu Apr 27 19:09:01 2017 +0200
@@ -249,6 +249,7 @@
  + New variable: AmmoTypeMax -- Maximum ammo type ID (useful to iterate through all ammo types, starting by 0)
  + Locale library: loc_noop -- Mark string for translation but don't translate it
  + Animate library: AnimInit([startAnimating]) -- New parameter startAnimating: if true, will start game in cinematic mode with most controls disabled. Must play an animation after that
+ * Fixed call: HideHog(gear) -- Fix crash when gear is invalid. Returns true on success or false otherwise
  * Removed call: SetAmmoStore -- Old undocumented function of questional use, has never been used
 
 0.9.21 -> 0.9.22
--- a/hedgewars/uScript.pas	Thu Apr 27 16:29:23 2017 +0200
+++ b/hedgewars/uScript.pas	Thu Apr 27 19:09:01 2017 +0200
@@ -2541,9 +2541,15 @@
     if CheckLuaParamCount(L, 1, 'HideHog', 'gearUid') then
         begin
         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
-        HideHog(gear^.hedgehog)
+        if (gear <> nil) and (gear^.hedgehog <> nil) then
+            begin
+            HideHog(gear^.hedgehog);
+            lua_pushboolean(L, true);
+            end
+        else
+            lua_pushboolean(L, false);
         end;
-    lc_hidehog := 0;
+    lc_hidehog := 1;
 end;
 
 function lc_restorehog(L: Plua_State): LongInt; Cdecl;