hedgewars/uCollisions.pas
changeset 5569 8313952b2811
parent 5568 badaac85f9d4
child 5572 47cc28299baa
--- a/hedgewars/uCollisions.pas	Sun Aug 14 23:06:00 2011 -0400
+++ b/hedgewars/uCollisions.pas	Sun Aug 14 23:52:45 2011 -0400
@@ -53,7 +53,7 @@
 function  calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): Boolean;
 
 implementation
-uses uConsts, uLandGraphics, uVariables, uDebug;
+uses uConsts, uLandGraphics, uVariables, uDebug, uGears;
 
 type TCollisionEntry = record
             X, Y, Radius: LongInt;
@@ -66,6 +66,7 @@
     ga: TGearArray;
 
 procedure AddGearCI(Gear: PGear);
+var t: PGear;
 begin
 if Gear^.CollisionIndex >= 0 then exit;
 TryDo(Count <= MAXRECTSINDEX, 'Collision rects array overflow', true);
@@ -78,7 +79,14 @@
     cGear:= Gear
     end;
 Gear^.CollisionIndex:= Count;
-inc(Count)
+inc(Count);
+// mines are the easiest way to overflow collision
+if (Count > (MAXRECTSINDEX-20)) then
+    begin
+    t:= GearsList;
+    while (t <> nil) and (t^.Kind <> gtMine) do t:= t^.NextGear;
+    if (t <> nil) and (t^.Kind = gtMine) then DeleteGear(t)
+    end;
 end;
 
 procedure DeleteCI(Gear: PGear);