Fix engine crash due to screwing up visual gears list in speechbubbles handler
authorunc0rr
Wed, 13 May 2009 19:53:45 +0000
changeset 2051 949fe7df09b6
parent 2050 8149802b4f14
child 2052 1f67933cb620
Fix engine crash due to screwing up visual gears list in speechbubbles handler
hedgewars/uVisualGears.pas
--- a/hedgewars/uVisualGears.pas	Wed May 13 01:30:08 2009 +0000
+++ b/hedgewars/uVisualGears.pas	Wed May 13 19:53:45 2009 +0000
@@ -253,17 +253,20 @@
 
 if Gear^.Timer = 0 then
 	begin
-	PHedgehog(Gear^.Hedgehog)^.SpeechGear:= nil;
+	if PHedgehog(Gear^.Hedgehog)^.SpeechGear = Gear then
+		PHedgehog(Gear^.Hedgehog)^.SpeechGear:= nil;
 	DeleteVisualGear(Gear)
 	end;
 end;
 
 procedure doStepSpeechBubble(Gear: PVisualGear; Steps: Longword);
 begin
-if (PHedgehog(Gear^.Hedgehog)^.SpeechGear <> nil) then DeleteVisualGear(PHedgehog(Gear^.Hedgehog)^.SpeechGear);
+with PHedgehog(Gear^.Hedgehog)^ do
+    if SpeechGear <> nil then SpeechGear^.Timer:= 0;
+
 PHedgehog(Gear^.Hedgehog)^.SpeechGear:= Gear;
 
-Gear^.Timer:= max(Length(Gear^.Text)*150,3000);
+Gear^.Timer:= max(Length(Gear^.Text) * 150, 3000);
 
 Gear^.Tex:= RenderSpeechBubbleTex(Gear^.Text, Gear^.FrameTicks, fnt16);