couple more use after frees for gear deletion.
authornemo
Fri, 11 Jan 2019 08:08:28 -0500
changeset 14559 397b2f4502c1
parent 14558 5ae97eab70eb
child 14562 3be619402d6b
couple more use after frees for gear deletion. also rearranged lines a bit and added a redundant exit to try to proof things a bit. more evidence we need rust.
hedgewars/uGearsHandlersMess.pas
--- a/hedgewars/uGearsHandlersMess.pas	Fri Jan 11 04:38:07 2019 +0100
+++ b/hedgewars/uGearsHandlersMess.pas	Fri Jan 11 08:08:28 2019 -0500
@@ -1191,9 +1191,7 @@
             end
         end
     else
-        begin
-        DeleteGear(Gear);
-        end
+		DeleteGear(Gear);
 end;
 
 procedure CreateShellForGear(Gear: PGear; startFrame: Longword);
@@ -2041,7 +2039,8 @@
                 or (getRandom(100) > cMineDudPercent) then
                     begin
                     doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Boom, Gear^.Hedgehog, EXPLAutoSound);
-                    DeleteGear(Gear)
+                    DeleteGear(Gear);
+					exit   // redundant but we've had too many delete gear bugs
                     end
                 else
                     begin
@@ -2084,7 +2083,8 @@
                     hwRound(Gear^.X) - SpritesData[sprFrozenAirMine].Width div 2,
                     hwRound(Gear^.Y) - SpritesData[sprFrozenAirMine].Height div 2,
                     sprFrozenAirMine, 0, 0, false, false, false, false);
-            DeleteGear(Gear)
+            DeleteGear(Gear);
+			exit
             end;
         doStepFallingGear(Gear);
         exit
@@ -2464,9 +2464,6 @@
         y := hwRound(Gear^.Y);
         hog:= Gear^.Hedgehog;
 
-        DeleteGear(Gear);
-        // <-- delete gear!
-
         if k = gtCase then
             begin
             doMakeExplosion(x, y, Gear^.Boom, hog, EXPLAutoSound);
@@ -2476,17 +2473,18 @@
         else if k = gtTarget then
             uStats.TargetHit()
         else if k = gtExplosives then
-                begin
-                doMakeExplosion(x, y, Gear^.Boom, hog, EXPLAutoSound);
-                for i:= 0 to 31 do
-                    begin
-                    dX := AngleCos(i * 64) * _0_5 * (getrandomf + _1);
-                    dY := AngleSin(i * 64) * _0_5 * (getrandomf + _1);
-                    AddGear(x, y, gtFlame, 0, dX, dY, 0);
-                    AddGear(x, y, gtFlame, gstTmpFlag, -dX, -dY, 0);
-                    end
-                end;
-            exit
+			begin
+			doMakeExplosion(x, y, Gear^.Boom, hog, EXPLAutoSound);
+			for i:= 0 to 31 do
+				begin
+				dX := AngleCos(i * 64) * _0_5 * (getrandomf + _1);
+				dY := AngleSin(i * 64) * _0_5 * (getrandomf + _1);
+				AddGear(x, y, gtFlame, 0, dX, dY, 0);
+				AddGear(x, y, gtFlame, gstTmpFlag, -dX, -dY, 0);
+				end
+			end;
+        DeleteGear(Gear);
+		exit
         end;
 
     if k = gtExplosives then
@@ -2865,7 +2863,7 @@
                 AddVisualGear(gX - 3 + Random(6), gY - 2, vgtSmoke);
 
         DeleteGear(Gear)
-        end;
+        end
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -2958,11 +2956,11 @@
             dY := _0;
             State := State or gstMoving;
             end;
-        DeleteGear(Gear);
         if (GetAmmoEntry(HHGear^.Hedgehog^, amParachute)^.Count >= 1) and ((Ammoz[HHGear^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and (HHGear^.Hedgehog^.MultiShootAttacks = 0) then
             HHGear^.Hedgehog^.CurAmmoType:= amParachute;
         isCursorVisible := false;
         ApplyAmmoChanges(HHGear^.Hedgehog^);
+        DeleteGear(Gear);
         exit
         end;
 
@@ -3042,7 +3040,7 @@
         // avoid to play forever (is this necessary?)
         StopSoundChan(Gear^.SoundChannel);
         DeleteGear(Gear)
-        end;
+        end
 end;
 
 procedure doStepAirAttack(Gear: PGear);
@@ -3085,12 +3083,12 @@
     if (Gear^.State and gstCollision) <> 0 then
         begin
         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Boom, Gear^.Hedgehog, EXPLAutoSound);
-        DeleteGear(Gear);
         {$IFNDEF PAS2C}
         with mobileRecord do
             if (performRumble <> nil) and (not fastUntilLag) then
                 performRumble(kSystemSoundID_Vibrate);
         {$ENDIF}
+        DeleteGear(Gear);
         exit
         end;
     if (GameTicks and $3F) = 0 then
@@ -3146,7 +3144,7 @@
         begin
         PlaySound(sndPlaced);
         DeleteGear(Gear);
-        AfterAttack;
+        AfterAttack
         end;
 
     HHGear^.State := HHGear^.State and (not (gstAttacking or gstAttacked));
@@ -3178,6 +3176,7 @@
         begin
         DeleteGear(Gear);
         AfterAttack;
+		exit
         end;
     inc(Gear^.Timer);
     if Gear^.Timer = 65 then
@@ -3281,12 +3280,12 @@
         begin
         hedgehog := Gear^.Hedgehog;
         //Msg := Gear^.Message and (not gmSwitch);
-        DeleteGear(Gear);
         ApplyAmmoChanges(hedgehog^);
 
         HHGear := CurrentHedgehog^.Gear;
         ApplyAmmoChanges(HHGear^.Hedgehog^);
         //HHGear^.Message := Msg;
+        DeleteGear(Gear);
         exit
         end;
 
@@ -4490,7 +4489,6 @@
                 Active := true;
                 State := State or gstMoving
                 end;
-            DeleteGear(Gear);
             if (GetAmmoEntry(HHGear^.Hedgehog^, amJetpack)^.Count >= 1) and ((Ammoz[HHGear^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and (HHGear^.Hedgehog^.MultiShootAttacks = 0) then
                 HHGear^.Hedgehog^.CurAmmoType:= amJetpack;
             isCursorVisible := false;
@@ -4500,6 +4498,7 @@
 //    Gear^.Tex:= RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(round(Gear^.Health / 20)) + '%', cWhiteColor, fntSmall)
 
 //AddCaption(trmsg[sidFuel]+': '+inttostr(round(Gear^.Health/20))+'%', cWhiteColor, capgrpAmmostate);
+            DeleteGear(Gear);
             end
 end;
 
@@ -4537,9 +4536,7 @@
     if Gear^.Timer < 2000 then
         inc(Gear^.Timer, 1)
     else
-        begin
-        DeleteGear(Gear);
-        end;
+        DeleteGear(Gear)
 end;
 
 procedure doStepBirdyFly(Gear: PGear);