Fix crash when hedgehog dies while switching from it
authorunc0rr
Thu, 05 Jul 2012 20:53:55 +0400
changeset 7341 d70478d265ec
parent 7339 5984b749ad9b
child 7343 ddb196c41387
Fix crash when hedgehog dies while switching from it
hedgewars/GSHandlers.inc
hedgewars/uAmmos.pas
--- a/hedgewars/GSHandlers.inc	Wed Jul 04 12:41:47 2012 -0400
+++ b/hedgewars/GSHandlers.inc	Thu Jul 05 20:53:55 2012 +0400
@@ -2750,16 +2750,17 @@
 procedure doStepSwitcherWork(Gear: PGear);
 var 
     HHGear: PGear;
+    hedgehog: PHedgehog;
     State: Longword;
 begin
     AllInactive := false;
 
     if ((Gear^.Message and (not gmSwitch)) <> 0) or (TurnTimeLeft = 0) then
         begin
-        HHGear := Gear^.Hedgehog^.Gear;
+        hedgehog := Gear^.Hedgehog;
         //Msg := Gear^.Message and (not gmSwitch);
         DeleteGear(Gear);
-        ApplyAmmoChanges(HHGear^.Hedgehog^);
+        ApplyAmmoChanges(hedgehog^);
 
         HHGear := CurrentHedgehog^.Gear;
         ApplyAmmoChanges(HHGear^.Hedgehog^);
--- a/hedgewars/uAmmos.pas	Wed Jul 04 12:41:47 2012 -0400
+++ b/hedgewars/uAmmos.pas	Thu Jul 05 20:53:55 2012 +0400
@@ -303,22 +303,23 @@
 
 procedure ApplyAngleBounds(var Hedgehog: THedgehog; AmmoType: TAmmoType);
 begin
-with Hedgehog do
-    begin
-    CurMinAngle:= Ammoz[AmmoType].minAngle;
-    if Ammoz[AmmoType].maxAngle <> 0 then
-        CurMaxAngle:= Ammoz[AmmoType].maxAngle
-    else
-        CurMaxAngle:= cMaxAngle;
+if Hedgehog.Gear <> nil then
+    with Hedgehog do
+        begin
+        CurMinAngle:= Ammoz[AmmoType].minAngle;
+        if Ammoz[AmmoType].maxAngle <> 0 then
+            CurMaxAngle:= Ammoz[AmmoType].maxAngle
+        else
+            CurMaxAngle:= cMaxAngle;
 
-    with Hedgehog.Gear^ do
-        begin
-        if Angle < CurMinAngle then
-            Angle:= CurMinAngle;
-        if Angle > CurMaxAngle then
-            Angle:= CurMaxAngle;
+        with Hedgehog.Gear^ do
+            begin
+            if Angle < CurMinAngle then
+                Angle:= CurMinAngle;
+            if Angle > CurMaxAngle then
+                Angle:= CurMaxAngle;
+            end
         end
-    end
 end;
 
 procedure SwitchToFirstLegalAmmo(var Hedgehog: THedgehog);
@@ -380,12 +381,12 @@
         AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo);
         if (Propz and ammoprop_NeedTarget) <> 0 then
             begin
-            Gear^.State:= Gear^.State or      gstHHChooseTarget;
+            if Gear <> nil then Gear^.State:= Gear^.State or      gstHHChooseTarget;
             isCursorVisible:= true
             end
         else
             begin
-            Gear^.State:= Gear^.State and not gstHHChooseTarget;
+            if Gear <> nil then Gear^.State:= Gear^.State and not gstHHChooseTarget;
             isCursorVisible:= false
             end;
         end