suggestion of mikade's - delete old mines if the collision array shows signs of filling up. This is kind of an edge case, esp now that array is up to 1024, but should prevent (easiest) way to crash by collision array overflow (endless mines/minestrikes).
authornemo
Sun, 14 Aug 2011 23:52:45 -0400
changeset 5569 8313952b2811
parent 5568 badaac85f9d4
child 5570 a1eb7555f439
suggestion of mikade's - delete old mines if the collision array shows signs of filling up. This is kind of an edge case, esp now that array is up to 1024, but should prevent (easiest) way to crash by collision array overflow (endless mines/minestrikes).
hedgewars/uCollisions.pas
--- 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);