Fix SetClanColor causing crashes and rendering bugs
authorWuzzy <Wuzzy2@mail.ru>
Mon, 21 Jan 2019 05:51:35 +0100
changeset 14641 7de65fa1f686
parent 14640 e6363b84b3fe
child 14642 bc4296649bbf
Fix SetClanColor causing crashes and rendering bugs
ChangeLog.txt
hedgewars/uScript.pas
hedgewars/uStore.pas
--- a/ChangeLog.txt	Mon Jan 21 02:52:09 2019 +0100
+++ b/ChangeLog.txt	Mon Jan 21 05:51:35 2019 +0100
@@ -88,6 +88,7 @@
  + Params explode, poison in the SpawnFake*Crate functions now optional and default to false
  + New global: InitHealth: Initial hog health value from game scheme (read-only)
  + Animate library: AnimOutOfNowhere: destX and destY are now optional (default: current position)
+ * Fix SetClanColor causing crashes and severe rendering bugs
  * Fix SetAmmoDelay not working properly when called after onGameStart
  * Fix DismissTeam not clearing team properly
 
--- a/hedgewars/uScript.pas	Mon Jan 21 02:52:09 2019 +0100
+++ b/hedgewars/uScript.pas	Mon Jan 21 05:51:35 2019 +0100
@@ -1358,7 +1358,8 @@
 function lc_setclancolor(L : Plua_State) : LongInt; Cdecl;
 var clan : PClan;
     team : PTeam;
-    hh   : THedgehog;
+    hht  : THedgehog;
+    hhp  : PHedgehog;
     i, j : LongInt;
 begin
     if CheckLuaParamCount(L, 2, 'SetClanColor', 'clan, color') then
@@ -1373,12 +1374,17 @@
             team:= clan^.Teams[i];
             for j:= 0 to cMaxHHIndex do
                 begin
-                hh:= team^.Hedgehogs[j];
-                if (hh.Gear <> nil) or (hh.GearHidden <> nil) then
+                hht:= team^.Hedgehogs[j];
+                hhp:= nil;
+                if (hht.Gear <> nil) then
+                    hhp:= team^.Hedgehogs[j].Gear^.Hedgehog
+                else if (hht.GearHidden <> nil) then
+                    hhp:= team^.Hedgehogs[j].GearHidden^.Hedgehog;
+                if (hhp <> nil) then
                     begin
-                    FreeAndNilTexture(hh.NameTagTex);
-                    hh.NameTagTex:= RenderStringTex(ansistring(hh.Name), clan^.Color, fnt16);
-                    RenderHealth(hh);
+                    FreeAndNilTexture(hhp^.NameTagTex);
+                    hhp^.NameTagTex:= RenderStringTex(ansistring(hhp^.Name), clan^.Color, fnt16);
+                    RenderHealth(hhp^);
                     end;
                 end;
             FreeAndNilTexture(team^.NameTagTex);
--- a/hedgewars/uStore.pas	Mon Jan 21 02:52:09 2019 +0100
+++ b/hedgewars/uStore.pas	Mon Jan 21 05:51:35 2019 +0100
@@ -619,8 +619,13 @@
 procedure RenderHealth(var Hedgehog: THedgehog);
 var s: shortstring;
 begin
-s:= IntToStr(Hedgehog.Gear^.Health);
 FreeAndNilTexture(Hedgehog.HealthTagTex);
+if Hedgehog.Gear <> nil then
+    s:= IntToStr(Hedgehog.Gear^.Health)
+else if Hedgehog.GearHidden <> nil then
+    s:= IntToStr(Hedgehog.GearHidden^.Health)
+else
+    exit;
 Hedgehog.HealthTagTex:= RenderStringTex(ansistring(s), Hedgehog.Team^.Clan^.Color, fnt16)
 end;