Fix list Z-order bug (not tested)
authorunc0rr
Fri, 07 May 2010 04:52:46 +0000
changeset 3442 69898c6ede14
parent 3441 f31225f99a06
child 3443 14d12df0d363
Fix list Z-order bug (not tested)
hedgewars/uGears.pas
--- a/hedgewars/uGears.pas	Fri May 07 02:33:42 2010 +0000
+++ b/hedgewars/uGears.pas	Fri May 07 04:52:46 2010 +0000
@@ -187,9 +187,6 @@
 procedure InsertGearToList(Gear: PGear);
 var tmp, ptmp: PGear;
 begin
-// this thing is broken, and the bug explains why you sometimes see grenade stuck in hog not behind hedgehog sprite
-// when there's only one gear in list, the next one is inserted right after it disregarding its Z value
-// TODO: fix the bug
     tmp:= GearsList;
     ptmp:= GearsList;
     while (tmp <> nil) and (tmp^.Z <= Gear^.Z) do
@@ -198,15 +195,19 @@
         tmp:= tmp^.NextGear
         end;
 
-    if ptmp <> nil then
+    if ptmp <> tmp then
         begin
         Gear^.NextGear:= ptmp^.NextGear;
         Gear^.PrevGear:= ptmp;
         if ptmp^.NextGear <> nil then ptmp^.NextGear^.PrevGear:= Gear;
         ptmp^.NextGear:= Gear
         end
-    else 
-        GearsList:= Gear
+    else
+        begin
+        Gear^.NextGear:= GearsList;
+        if Gear^.NextGear <> nil then Gear^.NextGear^.PrevGear:= Gear;
+        GearsList:= Gear;
+        end;
 end;
 
 procedure RemoveGearFromList(Gear: PGear);