Remove unnecessary loop in speechbubble code, thus removing use-after-freeing bug
authorunc0rr
Mon, 11 May 2009 19:42:29 +0000
changeset 2044 8548f5be2d72
parent 2043 1f2b91b5e7ef
child 2045 b0588498bc3a
Remove unnecessary loop in speechbubble code, thus removing use-after-freeing bug
hedgewars/uVisualGears.pas
--- a/hedgewars/uVisualGears.pas	Mon May 11 18:57:39 2009 +0000
+++ b/hedgewars/uVisualGears.pas	Mon May 11 19:42:29 2009 +0000
@@ -243,24 +243,20 @@
 end;
 
 procedure doStepSpeechBubbleWork(Gear: PVisualGear; Steps: Longword);
-var t: LongWord;
 begin
-for t:= 1 to Steps do
-    begin
-    dec(Gear^.Timer);
+if Gear^.Timer > Steps then dec(Gear^.Timer, Steps) else Gear^.Timer:= 0;
 
-    if (PHedgehog(Gear^.Hedgehog)^.Gear <> nil) then
-        begin
-        Gear^.X:= PHedgehog(Gear^.Hedgehog)^.Gear^.X+int2hwFloat(Gear^.Tex^.w div 2  - Gear^.FrameTicks);
-        Gear^.Y:= PHedgehog(Gear^.Hedgehog)^.Gear^.Y-int2hwFloat(16+Gear^.Tex^.h);
-        end;
+if (PHedgehog(Gear^.Hedgehog)^.Gear <> nil) then
+	begin
+	Gear^.X:= PHedgehog(Gear^.Hedgehog)^.Gear^.X + int2hwFloat(Gear^.Tex^.w div 2  - Gear^.FrameTicks);
+	Gear^.Y:= PHedgehog(Gear^.Hedgehog)^.Gear^.Y - int2hwFloat(16 + Gear^.Tex^.h);
+	end;
 
-    if Gear^.Timer = 0 then
-        begin
-        CurrentHedgehog^.SpeechGear:= nil;
-        DeleteVisualGear(Gear)
-        end;
-    end
+if Gear^.Timer = 0 then
+	begin
+	CurrentHedgehog^.SpeechGear:= nil;
+	DeleteVisualGear(Gear)
+	end;
 end;
 
 procedure doStepSpeechBubble(Gear: PVisualGear; Steps: Longword);