put back the old uteams cleanup, leaks and all, to worry about post-release since my attempt to use DeleteGear was running into the fact that that procedure does way more than just delete a gear. might need an explicit cleanup routine for both to call.
authornemo
Wed, 10 Dec 2014 08:05:45 -0500
changeset 10646 0be6442946b1
parent 10645 b8c73bacb31e
child 10647 90062f7a3103
put back the old uteams cleanup, leaks and all, to worry about post-release since my attempt to use DeleteGear was running into the fact that that procedure does way more than just delete a gear. might need an explicit cleanup routine for both to call.
hedgewars/uGearsList.pas
hedgewars/uTeams.pas
--- a/hedgewars/uGearsList.pas	Tue Dec 09 22:56:34 2014 -0500
+++ b/hedgewars/uGearsList.pas	Wed Dec 10 08:05:45 2014 -0500
@@ -23,8 +23,7 @@
 uses uFloat, uTypes, SDLh;
 
 function  AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
-procedure DeleteGear(Gear: PGear); inline;
-procedure DeleteGearStage(Gear: PGear; cleanup: boolean);
+procedure DeleteGear(Gear: PGear);
 procedure InsertGearToList(Gear: PGear);
 procedure RemoveGearFromList(Gear: PGear);
 
@@ -632,12 +631,7 @@
 ScriptCall('onGearAdd', gear^.uid);
 end;
 
-procedure DeleteGear(Gear: PGear); inline;
-begin
-DeleteGearStage(Gear, false)
-end;
-
-procedure DeleteGearStage(Gear: PGear; cleanup: boolean);
+procedure DeleteGear(Gear: PGear);
 var team: PTeam;
     t,i: Longword;
     k: boolean;
@@ -668,39 +662,17 @@
         end
     else*)
         begin
-        team:= Gear^.Hedgehog^.Team;
-        if not cleanup then
+        if ((CurrentHedgehog = nil) or (Gear <> CurrentHedgehog^.Gear)) or (CurAmmoGear = nil) or (CurAmmoGear^.Kind <> gtKamikaze) then
+            Gear^.Hedgehog^.Team^.Clan^.Flawless:= false;
+        if not CheckCoordInWater(hwRound(Gear^.X), hwRound(Gear^.Y)) then
             begin
-            if ((CurrentHedgehog = nil) or (Gear <> CurrentHedgehog^.Gear)) or (CurAmmoGear = nil) or (CurAmmoGear^.Kind <> gtKamikaze) then
-                Gear^.Hedgehog^.Team^.Clan^.Flawless:= false;
-            if not CheckCoordInWater(hwRound(Gear^.X), hwRound(Gear^.Y)) then
-                begin
-                t:= max(Gear^.Damage, Gear^.Health);
-                Gear^.Damage:= t;
-                if (((not SuddenDeathDmg) and (WaterOpacity < $FF)) or (SuddenDeathDmg and (SDWaterOpacity < $FF))) then
-                    spawnHealthTagForHH(Gear, t);
-                end;
-
-            // should be not CurrentHedgehog, but hedgehog of the last gear which caused damage to this hog
-            // same stand for CheckHHDamage
-            if (Gear^.LastDamage <> nil) and (CurrentHedgehog <> nil) then
-                uStats.HedgehogDamaged(Gear, Gear^.LastDamage, 0, true)
-            else if CurrentHedgehog <> nil then
-                uStats.HedgehogDamaged(Gear, CurrentHedgehog, 0, true);
-
-            inc(KilledHHs);
-            RecountTeamHealth(team);
-            if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Effects[heResurrectable] <> 0)  and
-            //(Gear^.Hedgehog^.Effects[heResurrectable] = 0) then
-            (Gear^.Hedgehog^.Team^.Clan <> CurrentHedgehog^.Team^.Clan) then
-                with CurrentHedgehog^ do
-                    begin
-                    inc(Team^.stats.AIKills);
-                    FreeAndNilTexture(Team^.AIKillsTex);
-                    Team^.AIKillsTex := RenderStringTex(ansistring(inttostr(Team^.stats.AIKills)), Team^.Clan^.Color, fnt16);
-                    end
+            t:= max(Gear^.Damage, Gear^.Health);
+            Gear^.Damage:= t;
+            if (((not SuddenDeathDmg) and (WaterOpacity < $FF)) or (SuddenDeathDmg and (SDWaterOpacity < $FF))) then
+                spawnHealthTagForHH(Gear, t);
             end;
 
+        team:= Gear^.Hedgehog^.Team;
         if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear = Gear) then
             begin
             AttackBar:= 0;
@@ -711,6 +683,7 @@
             end;
 
         Gear^.Hedgehog^.Gear:= nil;
+
         if Gear^.Hedgehog^.King then
             begin
             // are there any other kings left? Just doing nil check.  Presumably a mortally wounded king will get reaped soon enough
@@ -725,6 +698,25 @@
                     TeamGoneEffect(team^.Clan^.Teams[i]^)
                     end
             end;
+
+        // should be not CurrentHedgehog, but hedgehog of the last gear which caused damage to this hog
+        // same stand for CheckHHDamage
+        if (Gear^.LastDamage <> nil) and (CurrentHedgehog <> nil) then
+            uStats.HedgehogDamaged(Gear, Gear^.LastDamage, 0, true)
+        else if CurrentHedgehog <> nil then
+            uStats.HedgehogDamaged(Gear, CurrentHedgehog, 0, true);
+
+        inc(KilledHHs);
+        RecountTeamHealth(team);
+        if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Effects[heResurrectable] <> 0)  and
+        //(Gear^.Hedgehog^.Effects[heResurrectable] = 0) then
+        (Gear^.Hedgehog^.Team^.Clan <> CurrentHedgehog^.Team^.Clan) then
+            with CurrentHedgehog^ do
+                begin
+                inc(Team^.stats.AIKills);
+                FreeAndNilTexture(Team^.AIKillsTex);
+                Team^.AIKillsTex := RenderStringTex(ansistring(inttostr(Team^.stats.AIKills)), Team^.Clan^.Color, fnt16);
+                end
         end;
 with Gear^ do
     begin
--- a/hedgewars/uTeams.pas	Tue Dec 09 22:56:34 2014 -0500
+++ b/hedgewars/uTeams.pas	Wed Dec 10 08:05:45 2014 -0500
@@ -853,10 +853,11 @@
         for h:= 0 to cMaxHHIndex do
             with TeamsArray[i]^.Hedgehogs[h] do
                 begin
-                if Gear <> nil then
-                    DeleteGearStage(Gear, true);
+//                if Gear <> nil then
+//                    DeleteGearStage(Gear, true);
                 if GearHidden <> nil then
-                    DeleteGearStage(GearHidden, true);
+                    Dispose(GearHidden);
+//                    DeleteGearStage(GearHidden, true);
 
                 FreeAndNilTexture(NameTagTex);
                 FreeAndNilTexture(HealthTagTex);