hedgewars/uVisualGears.pas
changeset 4780 8571151411b3
parent 4772 02370ca8e92c
child 4782 603916ddf4b6
--- a/hedgewars/uVisualGears.pas	Wed Dec 29 17:27:33 2010 +0100
+++ b/hedgewars/uVisualGears.pas	Wed Dec 29 16:21:30 2010 -0500
@@ -328,6 +328,8 @@
     if Gear^.PrevGear <> nil then Gear^.PrevGear^.NextGear:= Gear^.NextGear
     else VisualGearsList:= Gear^.NextGear;
 
+    if lastVisualGearByUID = Gear then lastVisualGearByUID:= nil;
+
     Dispose(Gear);
 end;
 
@@ -524,13 +526,20 @@
 var vg: PVisualGear;
 begin
 VisualGearByUID:= nil;
+if uid = 0 then exit;
+if (lastVisualGearByUID <> nil) and (lastVisualGearByUID^.uid = uid) then
+    begin
+    VisualGearByUID:= lastVisualGearByUID;
+    exit
+    end;
 vg:= VisualGearsList;
 while vg <> nil do
     begin
     if vg^.uid = uid then
         begin
-            VisualGearByUID:= vg;
-            exit
+        lastVisualGearByUID:= vg;
+        VisualGearByUID:= vg;
+        exit
         end;
     vg:= vg^.NextGear
     end