merge'n'magic
authorsheepluva
Tue, 16 Dec 2014 23:41:26 +0100
changeset 10684 d403fd2f9a6f
parent 10680 4a4a82686e91 (current diff)
parent 10683 31a0e7efa17a (diff)
child 10685 ff3885faf013
merge'n'magic
hedgewars/uGearsHandlersRope.pas
--- a/hedgewars/uGearsHandlersRope.pas	Tue Dec 16 22:30:17 2014 +0100
+++ b/hedgewars/uGearsHandlersRope.pas	Tue Dec 16 23:41:26 2014 +0100
@@ -28,12 +28,22 @@
 uses uConsts, uFloat, uCollisions, uVariables, uGearsList, uSound, uGearsUtils,
     uAmmos, uDebug, uUtils, uGearsHedgehog, uGearsRender;
 
+const
+    IsNilHHFatal = true;
+
 procedure doStepRopeAfterAttack(Gear: PGear);
 var
     HHGear: PGear;
     tX:     hwFloat;
 begin
     HHGear := Gear^.Hedgehog^.Gear;
+    if HHGear = nil then
+        begin
+        OutError('ERROR: doStepRopeAfterAttack called while HHGear = nil', IsNilHHFatal);
+        DeleteGear(Gear);
+        exit()
+        end;
+
     tX:= HHGear^.X;
     if WorldWrap(HHGear) and (WorldEdge = weWrap) and
        ((TestCollisionXwithGear(HHGear, 1) <> 0) or (TestCollisionXwithGear(HHGear, -1) <> 0))  then
@@ -122,6 +132,12 @@
     wrongSide: boolean;
 begin
     HHGear := Gear^.Hedgehog^.Gear;
+    if HHGear = nil then
+        begin
+        OutError('ERROR: doStepRopeWork called while HHGear = nil', IsNilHHFatal);
+        DeleteGear(Gear);
+        exit()
+        end;
 
     if ((HHGear^.State and gstHHDriven) = 0) or
         (CheckGearDrowning(HHGear)) or (Gear^.PortalCounter <> 0) then
@@ -414,6 +430,13 @@
     Gear^.Elasticity := Gear^.Elasticity + _1;
 
     HHGear := Gear^.Hedgehog^.Gear;
+    if HHGear = nil then
+        begin
+        OutError('ERROR: doStepRopeAttach called while HHGear = nil', IsNilHHFatal);
+        DeleteGear(Gear);
+        exit()
+        end;
+
     DeleteCI(HHGear);
 
     if (HHGear^.State and gstMoving) <> 0 then
--- a/hedgewars/uGearsRender.pas	Tue Dec 16 22:30:17 2014 +0100
+++ b/hedgewars/uGearsRender.pas	Tue Dec 16 23:41:26 2014 +0100
@@ -168,6 +168,7 @@
 procedure DrawRope(Gear: PGear);
 var roplen, i: LongInt;
 begin
+    if Gear^.Hedgehog^.Gear = nil then exit;
     if (cReducedQuality and rqSimpleRope) <> 0 then
         DrawRopeLinesRQ(Gear)
     else
@@ -1204,9 +1205,12 @@
          gtAirBomb: DrawSpriteRotated(sprAirBomb, x, y, 0, DxDy2Angle(Gear^.dY, Gear^.dX));
         gtTeleport: begin
                     HHGear:= Gear^.Hedgehog^.Gear;
-                    if ((Gear^.State and gstAnimation) <> 0) then
-                        DrawSpriteRotatedF(sprTeleport, x + 1, y - 3, Gear^.Pos, hwSign(Gear^.dX), 0);
-                    DrawSpriteRotatedF(sprTeleport, hwRound(HHGear^.X) + 1 + WorldDx, hwRound(HHGear^.Y) - 3 + WorldDy, 11 - Gear^.Pos, hwSign(HHGear^.dX), 0);
+                    if HHGear <> nil then
+                        begin
+                        if ((Gear^.State and gstAnimation) <> 0) then
+                            DrawSpriteRotatedF(sprTeleport, x + 1, y - 3, Gear^.Pos, hwSign(Gear^.dX), 0);
+                        DrawSpriteRotatedF(sprTeleport, hwRound(HHGear^.X) + 1 + WorldDx, hwRound(HHGear^.Y) - 3 + WorldDy, 11 - Gear^.Pos, hwSign(HHGear^.dX), 0)
+                        end
                     end;
         gtSwitcher: DrawSprite(sprSwitch, x - 16, y - 56, (GameTicks shr 6) mod 12);
           gtTarget: begin