- Fix some collision bugs
authorunc0rr
Thu, 24 May 2007 20:33:07 +0000
changeset 521 bc8fd78d7598
parent 520 e83dfb7ffead
child 522 ca089787f59d
- Fix some collision bugs - Fix accessing to freed memory
hedgewars/GSHandlers.inc
hedgewars/uCollisions.pas
--- a/hedgewars/GSHandlers.inc	Thu May 24 19:41:51 2007 +0000
+++ b/hedgewars/GSHandlers.inc	Thu May 24 20:33:07 2007 +0000
@@ -760,7 +760,8 @@
       if Gear^.Timer = 0 then
          begin
          doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50, EXPLAutoSound);
-         DeleteGear(Gear)
+         DeleteGear(Gear);
+         exit
          end;
       dec(Gear^.Timer);
       end else // gsttmpFlag = 0
--- a/hedgewars/uCollisions.pas	Thu May 24 19:41:51 2007 +0000
+++ b/hedgewars/uCollisions.pas	Thu May 24 20:33:07 2007 +0000
@@ -191,7 +191,7 @@
    end;
 TestCollisionXKick:= false;
 
-if flag and (Gear^.dX > cHHKick) then
+if flag and (hwAbs(Gear^.dX) > cHHKick) then
    begin
    if Count = 0 then exit;
    mx:= hwRound(Gear^.X);
@@ -202,18 +202,18 @@
       if (Gear <> cGear) and
          (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius)) and
          ((mx > x) xor (Dir > 0)) then
-         if (cinfos[i].cGear^.Kind in [gtHedgehog, gtMine]) then
+         if (cGear^.Kind in [gtHedgehog, gtMine]) then
              begin
              Gear^.dX:= Gear^.dX {* _0_6};
              Gear^.dY:= Gear^.dY {* _0_6};
-             with cinfos[i].cGear^ do
+             with cGear^ do
                   begin
                   dX:= Gear^.dX {* _1_5};
                   dY:= Gear^.dY {* _1_5};
-                  State:= State and gstMoving;
+                  State:= State or gstMoving;
                   Active:= true
                   end;
-             DeleteCI(cinfos[i].cGear);
+             DeleteCI(cGear);
              exit
              end else exit(true)
    end
@@ -241,7 +241,7 @@
    end;
 TestCollisionYKick:= false;
 
-if flag and (Gear^.dX > cHHKick) then
+if flag and (hwAbs(Gear^.dX) > cHHKick) then
    begin
    if Count = 0 then exit;
    mx:= hwRound(Gear^.X);
@@ -252,18 +252,18 @@
       if (Gear <> cGear) and
          (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius)) and
          ((my > y) xor (Dir > 0)) then
-         if (cinfos[i].cGear^.Kind in [gtHedgehog, gtMine]) then
+         if (cGear^.Kind in [gtHedgehog, gtMine]) then
              begin
              Gear^.dX:= Gear^.dX {* _0_6};
              Gear^.dY:= Gear^.dY {* _0_6};
-             with cinfos[i].cGear^ do
+             with cGear^ do
                   begin
                   dX:= Gear^.dX {* _1_5};
                   dY:= Gear^.dY {* _1_5};
-                  State:= State and gstMoving;
+                  State:= State or gstMoving;
                   Active:= true
                   end;
-             DeleteCI(cinfos[i].cGear);
+             DeleteCI(cGear);
              exit
              end else exit(true)
    end